• Christopher Roberts

    (@christopherrobertswordpress)


    Hi everyone,

    I would like to know if anyone can work out how to remove the site title/name from the page title of single posts.

    The tile is fine on archives, the homepage and on single pages, however I don’t want it to show on single posts.

    The site is using Twenty Ten (Custom) and has slightly customised title code already.

    Here is the code:

    <title><?php
    
    	/*
    
    	 * Print the <title> tag based on what is being viewed.
    
    	 */
    
    	global $page, $paged;
    
    	// Add the word tag to tag pages.
    
    	$site_description = 'Tag - ';
    
    	if ( $site_description && ( is_tag() ) )
    
    		echo "  $site_description";
    
    	wp_title( '|', true, 'right' );
    
    	// Add the blog name.
    
    	bloginfo( 'name' );
    
    	// Add the blog description for the home/front page.
    
    	$site_description = get_bloginfo( 'description', 'display' );
    
    	if ( $site_description && ( is_home() || is_front_page() ) )
    
    		echo " | $site_description";
    
    	// Add a page number if necessary:
    
    	if ( $paged >= 2 || $page >= 2 )
    
    		echo ' | ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) );
    
    	?></title>

    All help is really appreciated – I have been trying for a while now and not getting anywhere!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi Christopher :)!
    You can likely do this in the CSS by using selectors for the single pages – can you post a link to your site?

    Hello Christopher,

    What you can do is use is_single() function.

    Your code would look something like this

    if(!is_single()) {
    //your code that you don't want to show on single pages
    }

    You probably want to fit bloginfo( ‘name’ ); in there if I’m right.

    Let me know if it works.

    Thread Starter Christopher Roberts

    (@christopherrobertswordpress)

    Hi WPyogi and prelevicm, thanks for the replies 🙂

    The site is Technology Bloggers.

    So how do I tell the blog to remove the tile if the page is_single…

    Christopher,

    Try this:

    instead of

    wp_title( '|', true, 'right' );
    	// Add the blog name.
    	bloginfo( 'name' );

    add this

    if(!is_single()) {
    	wp_title( '|', true, 'right' );
    
    	// Add the blog name.
    
    	bloginfo( 'name' );
    }

    I have not tested it.

    Or using CSS:

    .single #site-title {
       display: none;
    }

    But do you want the rest of the header section hidden too?

    Thread Starter Christopher Roberts

    (@christopherrobertswordpress)

    Hi both, thanks for the replies!

    @wpyogi, I didn’t explain myself properly, I meant the browser page title, (the code for the <title> tag) not the H1 title, although it’s pretty clever knowing you can strip the head of a page for certain pages!

    @prelevicm, great code, all pages stay the same, but a small problem – it completely strips all the title from single posts, i.e. the post name isn’t up there either!

    Thread Starter Christopher Roberts

    (@christopherrobertswordpress)

    @prelevicm, if I use this code:

    if(!is_single()) {
    			wp_title( '|', true, 'right' ); }
    
    		// Add the blog name.
    
    		bloginfo( 'name' );

    All pages remain the same except single posts which show only the blog title/name as the title. How can I reverse it so it shows the post title only?

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Remove blog name from title on single posts’ is closed to new replies.