Jump to content

Dynamic PHP Page titles and more?


kcmartz

Recommended Posts

I am in the process of redesigning my site from scratch. I want to have some script so I don't need to keep adding page titles. For example, I want the home page to say "Index | Site Name" and "About Me | Site Name". the 'about me' page would be 'about_me.php' and index.php as index. This would apply to all pages including Contact, and misc pages.

 

 

Also I want to have dynamic meta tags if possible. Simple-type dynamic. Like for the about page and contact page, things like "This is the (page name) page of Site Name. (Page name) is where you can get information on ___. (page name) blah blah blah..." You see what I mean? I would love something like that for the meta description.

 

 

Any help will be appreciated.

Link to comment
Share on other sites

$title = array();

$filename = __FILE__;

$filename = explode(".", $filename);

$filename = explode("_", $filename[0]);

foreach ($filename as &$part) {

    if (strlen($part))

        $part = strtoupper($part[0]) . strlen($part > 1) ? strtolower(substr($part, 1)) : "";

}

$title = implode(" ", $filename) . " | My Site Name";

 

Link to comment
Share on other sites

Include will work fine.  I had a bug in my code:

 

$filename = __FILE__;

$filename = explode(".", $filename);

$filename = explode("_", $filename[0]);

foreach ($filename as &$part) {

    if (strlen($part))

        $part = strtoupper($part[0]) . strlen($part) > 1 ? strtolower(substr($part, 1)) : "";

}

$title = implode(" ", $filename) . " | My Site Name";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.