Conditional page title from php functions?

Discussion in 'PHP' started by Mister Tut, Feb 9, 2006.

  1. #1
    I'm weak with PHP, but I've gone over a few tutorials trying to find the proper syntax for this and so far, no luck.

    My problem:

    Current code
    <title>Health-Hack.com | <?php wp_ozh_randomwords('quips') ?></title>
    Code (markup):
    I'm trying to make the code conditional so the above will be used on index.php, but on post pages "Health-Hack.com" is relpaced with
    <?php the_title(); ?>
    Code (markup):
    The best (doesn't break page, but doesn't work either) I've come up with is:
    <title>
    <?php
     if (is_home()) 
    echo " Health-Hack.com";
    else
    echo "<?php the_title(); ?>";
    ?>
     | <?php wp_ozh_randomwords('quips') ?>
    </title>
    Code (markup):
    As I said, I'm sucky at php. Could anyone show me how to get that the_title value to show, rather than the literal code itself?

    Thanks in advance.
     
    Mister Tut, Feb 9, 2006 IP
  2. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    echo "<?php the_title(); ?>";
    Code (markup):
    to

    
    echo the_title();
    
    Code (markup):
    that assumes the function the_title() does a RETURN at the end to output a value

    or just this

    
    <?php echo the_title() . " | " . wp_ozh_randomwords('quips'); ?>";
    
    Code (markup):
     
    TheHoff, Feb 9, 2006 IP
    Mister Tut likes this.
  3. Mister Tut

    Mister Tut Guest

    Messages:
    837
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you so much! Works like a charm.
     
    Mister Tut, Feb 9, 2006 IP