I am developing my first WP theme and would like to know how to display page name for every page/post instead of just "mysiteaddress.com"

How can I set that all my posts and pages show the tittle by default?

  • 1
    What code do you have now for your <title>? – coopersita Nov 10 '14 at 21:22
  • I use <title><?php wp_title(); ?></title> on all my pages but I'm getting page tittle in this format >>About, >>Contact, etc... How to delete the >> signs? – Damir Nov 11 '14 at 0:05

Your title is being set by something in your theme or a plugin attaching to the wp_title filter. You can further filter this value or override it entirely by using the same hook and a different priority that executes later.

// add a filter at priority 999 so it will presumably run last
add_filter( 'wp_title', 'my_wp_title', 999 );
function my_wp_title( $title ){
    // use the post to do things like get_the_title( $post->ID );
    global $post;

    // $title will be the current title if you want to str_replace() or something
    $title = "The new title";

    // return the title
    return $title;

The solution waas simple, just needed the right way of thinking about it.

I inserted the title code into the head of header.php instead of posting to every individual page template

<title><?php if (is_front_page() ) { bloginfo('name'); echo ' - ';  bloginfo('description'); } else {  wp_title(''); echo ' - '; bloginfo('name');  };?></title>

Try using:

<title><?php wp_title(''); ?></title>

This function can take different parameters> See wp_title()

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.