-
I can't see any reason for the absence of that variable, perhaps I have misunderstood your setup? I understood you are trying to do this inside a page template. Even if you write "echo $pagename" in the first line of header.php it should give you the value. What version of WP are you dealing with?
NOTE: This comment was originally posted at StackOverflow.com by AJJ
-
You could try a slightly different approach using get_query_var('pagename').
NOTE: This comment was originally posted at StackOverflow.com by AJJ
-
@AJweb: Yes, it's for a template that I'm building but I'm using the default template for testing, inside header.php. I get the impression that you haven't tested your solution. Do you see the page name when you put an <h1><?php echo $pagename ?></h1> right after the <body> tag in header.php ?
NOTE: This comment was originally posted at StackOverflow.com by Alkaline
-
@Alkaline: Your are right in one thing: My solutions don't work with all setups of WP. But you are wrong in thinking that I hadn't checked my solutions, I did. I post my findings in an edit of my answer so I can format it properly.
NOTE: This comment was originally posted at StackOverflow.com by AJJ
-
@AJweb: Thanks for the extra research. It adds crucial information. I am using static pages and that explains why $pagename isn't available.
NOTE: This comment was originally posted at StackOverflow.com by Alkaline
NOTE: This comment was originally posted at StackOverflow.com by Alkaline