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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RabidDog
Forum Newbie
Posts: 4
Joined: Wed Aug 19, 2009 7:21 pm

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

Post 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.
Last edited by RabidDog on Wed Jan 12, 2011 10:49 am, edited 3 times in total.
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

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

Post 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.
Last edited by AlanG on Wed Aug 19, 2009 8:04 pm, edited 2 times in total.
Szandor
Forum Newbie
Posts: 12
Joined: Wed Aug 19, 2009 5:58 pm

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

Post 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!
RabidDog
Forum Newbie
Posts: 4
Joined: Wed Aug 19, 2009 7:21 pm

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

Post 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!
RabidDog
Forum Newbie
Posts: 4
Joined: Wed Aug 19, 2009 7:21 pm

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

Post 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.
RabidDog
Forum Newbie
Posts: 4
Joined: Wed Aug 19, 2009 7:21 pm

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

Post 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?
Post Reply