Aiden Doyle Aiden Doyle - 6 months ago 29
HTML Question

Dynamic page title based on url

Hi lets say my url is www.mywebsite.com/category/music

how could I dynamically add a page title of the last part of the url which in this case is music. but as the the url changes how to grab the last part of that url.

Thanks

Omi Omi
Answer Source

Try this:

<title><?php echo basename($_SERVER['REQUEST_URI']); ?></title>

Or

 <title><?php echo  trim($_SERVER["REQUEST_URI"],"/");?></title>