How do you include meta tags function on pages?

by man5
5 replies
What I've done is have all my meta tags and title in the "head" page and I include that file on the index page, using php include.

That's all good. Now I am a little lost of how I can have different meta tags and titles for each page of the website. Can you tell me the php code to do that?

Thanks.
#function #include #meta #pages #tags
  • Profile picture of the author RobinInTexas
    Use PHP variables for the changeable tags and set the variable before you call each header, sidebar, footer etc.

    page1.php
    Code:
    dollarsign tag1 = '<meta name="keywords" content="page 1 keywords,internet marketing,affiliate marketing,search engine optimization,ebooks" /> ';
    
    include("includes/header.php");
    header.php

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html lang='en' xml:lang='en' xmlns="http://www.w3.org/1999/xhtml">
    <head>
    
    <?php echo dollarsign tag1 ;?>
    /* other  common stuff stuff*/
    The warriorforum software does not seem to allow $ tags in the code example
    Signature

    Robin



    ...Even if you're on the right track, you'll get run over if you just set there.
    {{ DiscussionBoard.errors[8728025].message }}
    • Profile picture of the author David Beroff
      Originally Posted by RobinInTexas View Post

      The warriorforum software does not seem to allow $ tags in the code example
      You can use the PHP tag in WF to display PHP, and then surround the dollar sign with backslashes, e.g.,

      PHP Code:
      $keyword = ... 
      Signature
      Put MY voice on YOUR video: AwesomeAmericanAudio.com
      {{ DiscussionBoard.errors[8745064].message }}
  • Profile picture of the author Brandon Tanner
    Another way to do it is to put the following code at the top of the "head" page...

    <?php $currentPage = pathinfo(__FILE__, PATHINFO_FILENAME); ?>

    That will get the file name of the current page (without the .php extension). So on your home page, for example, it would return "index".

    Then you can use conditional statements to customize the content on that page, based on what page you're on. For example...

    <?php
    if($currentPage == "index"){echo "<title>Home Page</title>";}
    if($currentPage == "about"){echo "<title>About Us</title>";}
    if($currentPage == "contact"){echo "<title>Contact Us</title>";}
    ?>


    etc. etc.

    It would probably be better to use switch/case if you have several pages, but you get the idea.
    Signature

    {{ DiscussionBoard.errors[8728062].message }}
  • Profile picture of the author man5
    Perfect. I will try that.
    Signature
    {{ DiscussionBoard.errors[8739258].message }}
  • Profile picture of the author shariarkhabir179
    Originally Posted by man5 View Post

    What I've done is have all my meta tags and title in the "head" page and I include that file on the index page, using php include.

    That's all good. Now I am a little lost of how I can have different meta tags and titles for each page of the website. Can you tell me the php code to do that?

    Thanks.
    Hi, thanks for the question and it was mine as well. I have got some important messages through the discussion here.
    {{ DiscussionBoard.errors[8746454].message }}

Trending Topics