I am using this code $pagename = get_query_var('pagename'); to get page name. Its working fine on localhost install under root directory. But when I have moved wordpress to run under subdirectory it returns no value


You shouldn't use get_query_var for getting the pagename (slug) - there is no guarantee that pagename will be set, depending on your permalink structure (or lack thereof).

Instead, check if the request is for a page, and then get the slug directly from the queried object:

if ( is_page() ) {
     $slug = get_queried_object()->post_name;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.