• Resolved jezthomp

    (@jezthomp)


    Odd one this, i’ll try and explain.

    Is there anyway i can have say home page.

    So it prints ‘Home’ in the main navigation.

    However, when you go to the home page the body title, the <?php the_title(); ?> actually says.

    Welcome to my site.

    Or whatever?

    Anyway to do it rather than taking out the title code and handcoding it in, in a template?

Viewing 9 replies - 1 through 9 (of 9 total)
  • <title><?php if(is_front_page()) echo 'Welcome to my site';
    else wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>
    Thread Starter jezthomp

    (@jezthomp)

    Wow thanks for that.

    Mind explaining what it does?

    Many thanks 🙂

    if(is_front_page()) = is this the front page of the site?
    If it is, show (echo) the welcome message.
    If it isn’t (else), show the post title followed 2 left angle quotes (&laquo;) and the blog name

    Thread Starter jezthomp

    (@jezthomp)

    I see thanks for that.

    I assume this would only work with the front page, could add a page id?

    For example this is page id 40 print this instead of page name?

    For a particular page, use is_page():

    `is_page(’40’)
    is_page(‘About Me’)

    So to include that in what esmi posted before the top line of what was posted before becomes….

    <title><?php if(is_front_page() || is_page('YOURPAGENAME')) echo 'Welcome to my site';

    …incase you wanted a break down …. 🙂

    The || simply means or, so if it’s the front page or a page named “YOURPAGENAME” (in the example).. *minus quotation..

    Thread Starter jezthomp

    (@jezthomp)

    Thanks esmi/t31os

    I need it to work in a particular way, not the browser title but in the main body title above the main body text.

    So..

    <h2>
    <?php if(is_front_page()) echo 'Welcome to'; ?> <?php bloginfo('name');  echo 'test name'; ?> </h2>

    Works great but there is no space before ‘test name’

    Also a range of pages needs its own title, can this be done.

    For example..

    If home page the above one..
    If is_page(23): print welcome to page 23,If is_page(24): print this is page 24,If is_page(25): print important page 25,If is_page(26): print different page 26,If is_page(27): print welcome to page 27 etc etc

    Can that be done?

    Gave it a go here but didnt work 🙁

    <h2>
    		<?php if(is_front_page()) echo 'Welcome to'; ?><?php bloginfo('name');  echo 'Test Blog'; ?>
    		<?php if(is_page(23) echo 'welcome to page 23';?>
    		<?php if(is_page(24) echo 'this is page 24'; ?>
    
    		</h2>

    Thanks 🙂

    Thread Starter jezthomp

    (@jezthomp)

    Manged to get this one working, the best way to do it though?

    <h2><?php
    
    if(is_page(21))
    {
    	echo 'Welcome to my home page';
    }
    elseif (is_page(23))
    {
    	echo 'this is page 23';
    }
    elseif (is_page(24))
    {
    	echo 'this is page 23';
    }
    
    ?></h2>

    Nothing wrong with what you have…

    I’d personally do it this way, but there’s not going to be any measurable difference between the 2 pieces of code..

    <?php
    if(is_page(21)) { $title_msg = 'Welcome to my home page'; }
    elseif (is_page(23)) { $title_msg = 'this is page 23'; }
    elseif (is_page(24)) { $title_msg = 'this is page 24'; }
    else { $title_msg = 'Default message'; }
    ?>
    <h2><?php echo $title_msg; ?></h2>
Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Title different to button?’ is closed to new replies.