Page 1 of 2 12 LastLast
Results 1 to 25 of 41
  1. #1
    ABW Ambassador
    Join Date
    June 30th, 2007
    Location
    Syracuse, NY
    Posts
    677
    How to use Meta tags with PHP?
    Sorry if this is a total newbie question, but supposedly meta tags need to be put in the head, but the head is in my header.php file which is included on all my pages.

    Would they work by putting them before the html:
    Code:
    <?php include('header.php'); ?>
    <meta name="keywords" content="key, word">
    <meta name="description" content="blah blah blah.">
    <title>Title</title>
    <html>
    The title does work like that, I've found out. So maybe they work like this too?

    Thanks.

  2. #2
    ABW Ambassador PatrickAllmond's Avatar
    Join Date
    September 20th, 2005
    Location
    OKC
    Posts
    1,219
    If you want the same metatags in all of the pages then I'd put them in that header.php.
    ---
    This response was masterly crafted via the fingers of Patrick Allmond who believe you should StopDoingNothing starting today.
    ---
    Focus Consulting is where I roll | Follow @patrickallmond on Twitter
    Search Engine Marketing | Search Engine Optimization | Social Media | Online Video

  3. #3
    ABW Ambassador
    Join Date
    June 30th, 2007
    Location
    Syracuse, NY
    Posts
    677
    Yeah, but I want it to be different for each page. The description and keywords. Think it could work like this?

    Thanks for the reply.

  4. #4
    ABW Ambassador PatrickAllmond's Avatar
    Join Date
    September 20th, 2005
    Location
    OKC
    Posts
    1,219
    Yes... then it will work fine.
    ---
    This response was masterly crafted via the fingers of Patrick Allmond who believe you should StopDoingNothing starting today.
    ---
    Focus Consulting is where I roll | Follow @patrickallmond on Twitter
    Search Engine Marketing | Search Engine Optimization | Social Media | Online Video

  5. #5
    ABW Ambassador
    Join Date
    June 30th, 2007
    Location
    Syracuse, NY
    Posts
    677
    Okay, thanks.

    More work this way, I know, LOL.

  6. #6
    .
    Join Date
    January 18th, 2005
    Posts
    2,973
    My understanding is that the meta tags are requred to be inside the header (between the <head> and </head> tags).

    Presumably you could accomplish the same thing by putting the <HTML><HEAD> string at the beginning of your meta-tags, and then exclude that from the include file.

  7. #7
    ABW Ambassador
    Join Date
    June 30th, 2007
    Location
    Syracuse, NY
    Posts
    677
    Eeep, you sure? I could always just do this then, just in case.
    <head>
    <meta name="keywords" content="key, word">
    <meta name="description" content="blah blah blah.">
    <title>Title</title>
    <?php include('header.php'); ?>
    <html>
    And have the </head> in my header.php file, should work fine as well?

    Thanks to you as well.

    P.S. Am I confused, the <html> tag should go before the <head> tag? Not sure why I'm putting it where I have it, oy, lol.

  8. #8
    Member
    Join Date
    December 12th, 2007
    Location
    Fort Smith, AR
    Posts
    57
    Quote Originally Posted by Hardaka
    Eeep, you sure? I could always just do this then, just in case.

    And have the </head> in my header.php file, should work fine as well?

    Thanks to you as well.

    P.S. Am I confused, the <html> tag should go before the <head> tag? Not sure why I'm putting it where I have it, oy, lol.
    Actually, I'm pretty sure that the head tag goes inside the html tag. Here is what the tags on my pages look like.
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
      <title>Your Site</title>
      <meta http-equiv="Content-Type" content="text/html; charset =iso-8859-15" />
      <meta name="keywords" content="what you want" />
      <meta name="description" content="what you want" />
       </head>

  9. #9
    .
    Join Date
    January 18th, 2005
    Posts
    2,973
    My understanding is that the <head> tag and all header tags are supposed to come after the <HTML> tag, not before it. I know that most browsers are extremely tolerant of coding errors that misplace tags, but I would certainly not count on this.

    See http://www.w3.org/TR/html401/struct/global.html for the "official" reference; I found this plus other relevant resources at http://www.google.com/search?q=html+head

  10. #10
    ABW Ambassador PatrickAllmond's Avatar
    Join Date
    September 20th, 2005
    Location
    OKC
    Posts
    1,219
    duhh.... mark et al are correct. I didn't pay attention to the actual positioning.
    ---
    This response was masterly crafted via the fingers of Patrick Allmond who believe you should StopDoingNothing starting today.
    ---
    Focus Consulting is where I roll | Follow @patrickallmond on Twitter
    Search Engine Marketing | Search Engine Optimization | Social Media | Online Video

  11. #11
    ABW Veteran Mr. Sal's Avatar
    Join Date
    January 18th, 2005
    Posts
    6,795
    <html>
    <head>
    <title>Title</title>
    <meta name="keywords" content="key, word">
    <meta name="description" content="blah blah blah.">
    </head>

    <body>
    <?php include('header.php'); ?>



    </body>
    </html>
    ...

  12. #12
    Member
    Join Date
    December 12th, 2007
    Location
    Fort Smith, AR
    Posts
    57
    Precicely what I said.
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    This is an opening html tag, just with a few extra options.

  13. #13
    ABW Ambassador
    Join Date
    June 30th, 2007
    Location
    Syracuse, NY
    Posts
    677
    Thank you all for the extra input.

    Though Mr. Sal, you kind of confused me..

    The include for the header.php should go in the body? I have more code in my head, that is the same for all pages, so it seemed best to keep that in the head in the header. Just the metas for each different page I needed to work around.

    Is having the header before the body an error? Works fine on Opera, IE, FF.. unless they're ignoring the error? lol sorry.

    Can anyone tell I'm self taught? (besides when I'm asking for help on here, LOL)

  14. #14
    Member
    Join Date
    December 12th, 2007
    Location
    Fort Smith, AR
    Posts
    57
    I may be wrong, but from what I've seen, the php tags go before the html tags, and before the head tags. Here is an example I found.

    Code:
    <?php
      require_once 'Pager/Pager.php';
      
      //create dummy array of data
      $myData = array();
      for ($i=0; $i<200; $i++) {
      	$myData[] = $i;
      }
      
      $params = array(
      	'itemData' => $myData,
      	'perPage' => 10,
     	'delta' => 8,			 // for 'Jumping'-style a lower number is better
      	'append' => true,
      	//'separator' => ' | ',
      	'clearIfVoid' => false,
      	'urlVar' => 'entrant',
      	'useSessions' => true,
      	'closeSession' => true,
      	//'mode'  => 'Sliding',	//try switching modes
      	'mode'  => 'Jumping',
      
      );
      $pager = & Pager::factory($params);
      $page_data = $pager->getPageData();
      $links = $pager->getLinks();
      
      $selectBox = $pager->getPerPageSelectBox();
      ?>
      
      <html>
      <head>
      <title>new PEAR::Pager example</title>
      </head>
      <body>
      </body>
      </html>
    Notice that the php code is before the html tag and that the head tag is in the html tag.
    Last edited by animatic1; December 15th, 2007 at 04:03 AM. Reason: Added an example

  15. #15
    ABW Ambassador
    Join Date
    June 30th, 2007
    Location
    Syracuse, NY
    Posts
    677
    That's PHP beyond what I do, I think, LOL.

    But, you're right. Experts can correct me if this is wrong, but if I put anything before my php include for my header, I get this symbol appearing at the top of me webpage in IE.
    
    I actually remember having this problem before, the fix was putting the php include first. (rest of my php includes in the body have no problems)

    So I think I need to go with this:
    Code:
    <?php include('header.php'); ?>
    <meta name="keywords" content="key, word">
    <meta name="description" content="blah blah blah.">
    <title>Title</title>
    </head>
    <body>
    Content.
    </body>
    </html>
    And my header.php would look something like:
    Code:
    <html>
    <head>
    Code, code, code..
    So I have the closing tag for the head, on the page I call the header too. Pretty sure that should work, will try after I've had a chance to sleep, lol.

  16. #16
    Member
    Join Date
    December 12th, 2007
    Location
    Fort Smith, AR
    Posts
    57
    Quote Originally Posted by Hardaka
    Sorry if this is a total newbie question, but supposedly meta tags need to be put in the head, but the head is in my header.php file which is included on all my pages.

    Would they work by putting them before the html:
    Code:
    <?php include('header.php'); ?>
      <meta name="keywords" content="key, word">
      <meta name="description" content="blah blah blah.">
      <title>Title</title>
      <html>
    The title does work like that, I've found out. So maybe they work like this too?

    Thanks.
    Is your header.php file one you created? Or was it included along with other files in your host's website builder? The header.php included in my website builder files is for this>>

    * Net_DNS_Header object definition {{{ */
    /**
    * Object representation of the HEADER section of a DNS packet
    *
    * The Net_DNS::Header class contains the values of a DNS packet. It parses
    * the header of a DNS packet or can generate the binary data
    * representation of the packet. The format of the header is described in
    * RFC1035.

  17. #17
    ABW Ambassador
    Join Date
    June 30th, 2007
    Location
    Syracuse, NY
    Posts
    677
    I built my site orignally with Wordpress, and I had zero knowledge of CSS and PHP at the time. I learned CSS (and PHP sorta) while taking a template and changing it around to what I wanted. Then I found out Wordpress won't let you do some things I wanted to do, so I took that template and with some help, made it PHP/CSS minus all of Wordpress' crap.

    Although, in my header.php file, I do have some content for the website. Banner and nav bar. From this thread, I'm thinking I should make a new php file for the top banner and nav bar, and turn my header.php into one that is only calling my javascript file and css style sheet and any other needed code.

    Edit: LOL, no sleep yet.. had to try and see if the method I mentioned above will work, and it is! In IE, FF, and Opera.

    Any errors the browsers are ignoring or should be good?
    Last edited by Hardaka; December 15th, 2007 at 05:09 AM.

  18. #18
    ABW Ambassador
    Join Date
    January 18th, 2005
    Location
    Los Angeles
    Posts
    4,053
    Quote Originally Posted by Hardaka
    I built my site orignally with Wordpress, and I had zero knowledge of CSS and PHP at the time. I learned CSS (and PHP sorta) while taking a template and changing it around to what I wanted. Then I found out Wordpress won't let you do some things I wanted to do, so I took that template and with some help, made it PHP/CSS minus all of Wordpress' crap.
    You can now use custom page titles and meta tags with WordPress for each post and page. There's a plug-in for it, for WP 2.3.

    You can use unique titles within the header.php include if you define the variables before the <html> tag, which won't affect the page and won't put the CSS into quirks mode, since it's never delivered to browsers.

    <?php
    $title="Your favorite widgets and gadgets";
    $description="Buy cheap widgets and gadgets online.";
    ?>

    Then call up the include. This will be in the header.inc.php include for the doctype declaration and the head section (along with the rest of the head section tags), using those variables, which are above the header include, first thing on the page with any other variables that need to be defined individually:

    <html>
    <head>
    <title><$php print $title;?></title>
    <meta name="description" content=<?php print $description;?>
    </head>

    Or they could be in a MySQL database, but I haven't found out how yet.

  19. #19
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    What Marcia said. Or you can store all your titles and meta tags in a flat text database and have a little PHP snippet that pulls the appropriate tags for the current page. But of course mySQL is the best way to go.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  20. #20
    Moderator BurgerBoy's Avatar
    Join Date
    January 18th, 2005
    Location
    jacked by sylon www.sylonddos.weebly.com
    Posts
    9,618

    Vietnam Veteran 1966-1970 USASA
    ABW Forum Rules - Advertise At ABW

  21. #21
    ABW Ambassador
    Join Date
    January 18th, 2005
    Location
    Los Angeles
    Posts
    4,053
    I was wrong in the syntax, tried it out of memory.

    Here it is off a working page, what's used on the page:

    <?php
    $title="Your page title goes here";
    $description="Your description goes here.";
    $keywords="keyword1, keyword 2, keyword 3";
    $content="filename for content">
    // Additional variables as needed
    include("template.php");
    ?>

    What's in the top of template.php:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title><?php echo $title; ?></title>
    <meta name="description" content="<?php echo $description; ?>">
    <meta name="keywords" content="<?php echo $keywords; ?>">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" href="includes/styles.css">
    </head>

    Note: That's just with one main template file being used, with the "section" includes called within that one (testing for a site makeover). First attempt at this, and it's really got that text for the title and meta tags so far.

    ====================

    For WordPress, I installed this plugin on a blog this week, and to my surprise, it puts the fields in a section right under where you do a post, so you do your tags and title at the same time as the blog post. Works perfectly.

    http://wp.uberdose.com/2007/03/24/all-in-one-seo-pack/

    I used it on WP 2.3 which it was just upgraded to for me last weekend.
    Last edited by webworker; December 15th, 2007 at 08:55 AM.

  22. #22
    ABW Ambassador
    Join Date
    June 30th, 2007
    Location
    Syracuse, NY
    Posts
    677
    Thank you for all the feedback Marcia, although.. I guess I wasn't very clear. I'm not using Wordpress anymore. Sorry if I didn't make that clear enough, was 4 am at the time, LOL.

    The code you just posted is for non wordpress websites?

    I tried it out.. and while it seems to work, it leaves me with this symbol in FF.
    
    Doesn't show up in Opera or IE for a change. So, so far.. the only working solution I have is this one..
    Header.php
    Code:
    <html>
    <head>
    Code, code, code..
    With the index file adding in the meta tags and closing the head.
    Code:
    <?php include('header.php'); ?>
    <meta name="keywords" content="key, word">
    <meta name="description" content="blah blah blah.">
    <title>Title</title>
    </head>
    <body>
    Content.
    </body>
    </html>
    No funny symbols and the title shows up. No idea about the meta tags yet, since I don't have the website on google to check, but is this method fine? It works, but I don't want to be doing it in a way that is in error and end up having browsers decide to stop ignoring the errors, lol.

    Sorry and thanks y'all.

  23. #23
    Action Jackson - King of the World
    Join Date
    January 18th, 2005
    Posts
    2,201
    <html>
    <head>

    <title><?php echo stripslashes ($_GET['interest']); ?></title>

    <meta name="description" content="Buy <?php echo stripslashes ($_GET['interest']); ?> from my website. Purchase <?php echo stripslashes ($_GET['interest']); ?> today!">

    <meta name="keywords" content="<?php echo stripslashes ($_GET['interest']); ?>,other keywords">

    </head>

  24. #24
    Member
    Join Date
    December 12th, 2007
    Location
    Fort Smith, AR
    Posts
    57
    The one question that I need to ask is, are html tags allowed in php script? I mean will the php script execute html tags within it?

    Quote Originally Posted by Hardaka
    Code:
      <html> <head> Code, code, code..

  25. #25
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    Quote Originally Posted by jackson992
    <html>
    <head>

    <title><?php echo stripslashes ($_GET['interest']); ?></title>

    <meta name="description" content="Buy <?php echo stripslashes ($_GET['interest']); ?> from my website. Purchase <?php echo stripslashes ($_GET['interest']); ?> today!">

    <meta name="keywords" content="<?php echo stripslashes ($_GET['interest']); ?>,other keywords">

    </head>
    Why would you ever display a query string as your page title and meta tags? Somebody could easily damage your brand by linking to yourpage.php?interest=Nude+Naked+Models and creating an entry for it in the search engines. Never do this.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Meta Tags
    By Incentials in forum Search Engine Optimization
    Replies: 18
    Last Post: January 20th, 2008, 12:02 PM
  2. Meta Tags
    By Apool in forum Search Engine Optimization
    Replies: 5
    Last Post: October 8th, 2003, 10:24 AM
  3. Meta tags ?
    By Adam Ward in forum Suspicious Activity!
    Replies: 1
    Last Post: June 23rd, 2002, 09:44 AM
  4. Meta Tags
    By RomanXIII in forum Search Engine Optimization
    Replies: 10
    Last Post: April 24th, 2002, 06:31 PM
  5. Meta Tags
    By cazzie in forum Midnight Cafe'
    Replies: 4
    Last Post: November 10th, 2001, 11:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •