How to get the current Wordpress Page Name? 8
Mar5
A friend had the question tonight “How do i pull the pagename of the current page in wordpress?.”
Turns out he wanted to display different padding around his paragraphs on different pages.
Here is the solution I came up with:
The code, which can be placed at the top of header.php in your theme.
<?php list($page_name,) = explode('/', trim(array_shift(explode('?', $_SERVER['REQUEST_URI'])), '/')); $page_name = (!empty($page_name)?$page_name:'homepage'); ?> ?>
Then to echo the page_name in a div or something…
<div id="Site" class="page_<?=$page_name;?>">
Good luck wordpress fanatics