Php Code For Echoing Page Title Elsewhere

Discussion in 'PHP' started by jasonwilks, Jan 26, 2013.

  1. #1
    Hello, I need php code for echoing the text between the <title></title> tags elsewhere on the page.

    And this tag as well: <meta name="description" content="this text needs echoed elsewhere on the current page through php.." />

    Basically what I am trying to do is echo the title from the title tags, and the description from the meta description tag into the facebook meta property data, like this:
    <meta property="og:title" content="I NEED THE TITLE ECHOED HERE FROM THE TITLE TAG" />
    <meta property="og:description" content="AND THE DESCRIPTION ECHOED HERE FROM THE META DESCRIPTION TAG" />
    And that's it! I assume this shouldn't be too difficult!
     
    jasonwilks, Jan 26, 2013 IP
  2. mokah

    mokah Active Member

    Messages:
    88
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    65
    #2
    Cool. Just do it like this:
    Set the variable at the top of the page.
    <?php $title = "Your Title"; ?>
     
    Echo the variable wherever you want.
    <?php echo $title; ?>
     
    You can do the same with the description or anything else.
    <?php $desc = "Your description"; ?>
     
    Echo
    <?php echo $desc; ?>
    PHP:
     
    mokah, Jan 26, 2013 IP
  3. jasonwilks

    jasonwilks Well-Known Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #3
    Thanks it was just what I needed!
     
    jasonwilks, Jan 26, 2013 IP