Aiden Doyle Aiden Doyle - 18 days ago 7
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

Try this:

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

Or

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