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


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

  • Thank you :). it works ..may i ask what this filter does and how it is modified ?apply_filters( 'single_post_title', string $post_title, object $post ) – Latheesh V M Villa Jun 9 '18 at 17:13
  • Your original apply_filters code is not correct. The answer shows the correct format of the add_filter function. See the docs for how add_filter works. – Rick Hellewell Jun 10 '18 at 1:54

If you are referring to the wp_title function called in the title tag in the head part of the header.

function wpdocs_filter_wp_title( $title, $sep ) {
    global $paged, $page;

    if ( is_feed() )
        return $title;

    // Add the site name.
    $title .= get_bloginfo( 'name' );

    // Add whatever else you want
    $title .= $sep . 'whatever other information';

    return $title;
add_filter( 'wp_title', 'wpdocs_filter_wp_title', 10, 2 );

Here is the documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.