How to change the blog title with add_filter? details below

i want to add a prefix to all the blog title by modifying the all ready applied filter .

when i searched i got this:

apply_filters( 'single_post_title', string $post_title, object $post )

what action do i have to modify this?

add_filter('single_post_title', 'my_title');

function my_title() {}

i want this done without the javascript ..
any help is really appreciated
thanks

2 Answers
2

With the filter single_post_title, you can change the page/post title that is set in the <head><title>Page title</title></head>.

If you want to change the title that you see in the page header. ( Which i think you want to do).

Use this filter:

add_filter('the_title', 'modify_all_titles', 10, 2);

function modify_all_titles($title, $id) {
  return 'SOME TEXT BEFORE TITLE | '.$title;
}

Place this code in the functions.php (use a child theme).

Regards, Bjorn

Leave a Comment