Page 1 of 1

[solved] modify blog header.php to display post name only

Posted: Wed Aug 19, 2009 7:30 pm
by RabidDog
hi,
usually a wordpress blog shows the following:
homepage title: BLOG_NAME
individual post page: BLOG_NAME - POST_NAME

I want mine to display the blog name for the title on the home page and each post page to ONLY have the post name for the title. I've modified my header.php file and I've gotten this far...

homepage title: ~ BLOG_NAME
individual post page title: POST_NAME ~ BLOG_NAME

but I want the individual post page to only be: POST_NAME
(and not have the blog name after it!)

Can you see what I should change to do this?

Code: Select all

<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    
    <title><?php if (is_single() || is_page() || is_archive()) { wp_title('',true); } ?> ~ <?php bloginfo('name'); ?></title>
    
    <meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats -->
    
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/custom.css" type="text/css" media="screen" />
    <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
 
    <?php wp_head(); ?>
</head>
<body class="custom">
 
<div id="container">
 
    <div id="masthead">
        <h1><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></h1>
        <h3><?php bloginfo('description'); ?></h3>
    </div>
 
    <ul id="nav">
        <li <?php if (is_home()) echo('class="current_page_item" '); ?>><a href="<?php bloginfo('url'); ?>">front page</a></li>
        <?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>
        
        
    </ul>
    
    <div id="header_img">
        <img src="<?php bloginfo('template_url'); ?>/images/my-header.jpg" width="770px" height="140px" alt="<?php bloginfo('name'); ?>" title="<?php bloginfo('name'); ?> " />
         
</div>
Thanks in advance.

FYI: for reference, anyone wanting to see how it worked, my blog is the Trade Show Guru.

Re: modify blog header.php to show post name only - help?

Posted: Wed Aug 19, 2009 8:01 pm
by AlanG
Just modify the title tag like this:

Code: Select all

<title><?php if (is_page() || is_archive()) { wp_title('',true); } else if(is_single()) { bloginfo('name'); } ?></title>
The is_single() function checks for single post pages. So on those pages only, you will display only the post title, not the blog's title.

Re: modify blog header.php to show post name only - help?

Posted: Wed Aug 19, 2009 8:03 pm
by Szandor
I'd change the IF clause in your title a bit, from this:

Code: Select all

<title><?php if (is_single() || is_page() || is_archive()) { wp_title('',true); } ?> ~ <?php bloginfo('name'); ?></title>
to this:

Code: Select all

<title><?php if (is_single() || is_page() || is_archive()) { wp_title('',true); } else { echo bloginfo('name'); } ?></title>
Try it and see if it works!

Re: modify blog header.php to show post name only - help?

Posted: Wed Aug 19, 2009 10:01 pm
by RabidDog
hi AlanG and Szandor,
Thanks. I'm going to try to figure out what Alan changed :) and try that first and see what happens, then I'll try Szandor's suggestion, and I'll report back. Fingers crossed!

Re: modify blog header.php to show post name only - help?

Posted: Thu Aug 20, 2009 11:34 am
by RabidDog
You guys ROCK! Now I know where to come with my PHP problems. :D

Many Thanks to Szandor. His suggestion worked! THANK YOU.

FYI - I tried Alan's suggestion but I got this:
homepage - blank title
post pages - blog name is title
category and archives - just category and archive name.

category and archives were what I wanted, but the blog title and post titles were wrong.

with Szandor's solution my blog title is just the blog name, and the post titles are just the post names, as are the category titles just the categories.

AWESOME.

Re: [solved] modify blog header.php to display post name only

Posted: Thu Aug 20, 2009 11:38 am
by RabidDog
I just edited the topic to add "[solved]" to the thread name. Is there a way to thank Szandor or somehow give him a "gold star" on his user profile?