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
https://forums.phpfreaks.com/topic/263096-dynamic-php-page-titles-and-more/
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";

 

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.