I'm using wp_title() in the body of my theme to print out the page title name at the top of the page, way before the content. This unfortunately also prints out the site name, which is redundant in my use case.

Essentially I'm going for this to be dynamic on each page:

Site Name >> Page Name

instead of

Site Name >> Page NameSite Name

I modified the filter built into my boilerplate theme adjusting this:

// Otherwise, let's start by adding the site name to the end:
    $title .= get_bloginfo( 'name', 'display' );

    // If we have a site description and we're on the home/front page, add the description:
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) )
        $title .= " $separator " . $site_description;

But this unfortunately also removed it from the <title> attribute in my <head> tag.

is there a way I can modify this filter to only do a certain action when it's in the body of the page?

  • 1
    Can you please edit your question to post your full code, in context? Is this inside of the <title> tag, or a callback to the wp_title filter, or what? – Chip Bennett Nov 18 '13 at 22:48
  • Sorry for not clarifying, it's inside the <body> tag. Under header.php where it echoes out the site name, and by default, the tagline too. – user32405 Nov 19 '13 at 1:47

The $post object is available outside the loop so you should be able to echo get_the_title( $post->ID ); in the body.

| improve this answer | |
  • I forgot that Wordpress uses pages like posts, and this would work like a charm. Thanks! – user32405 Nov 19 '13 at 1:46
  • Looks like I need to do a combination of this, along with checking if the page is a specific one, to avoid posting the title of a post that's on the front page. – user32405 Nov 19 '13 at 20:48

Your Answer

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