In this code snippet we will share how to get current page name in WordPress. If you want to get current page name, You need to use some line of code to get get current page name.

The WP global variable $pagename should be available for you.

Use the following code to get current page name:

//To get current page name
$pagename = get_query_var('pagename');  
if ( !$pagename && $id > 0 ) {  
    // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object  
    $post = $wp_query->get_queried_object();  
    $pagename = $post->post_name;  
}

If you feel this snippet useful? Any questions or suggestions? Do let me know your thoughts via comments.

How to Get Current Page Name in WordPress Click To Tweet Don't forget to subscribe via email so you never miss a post! You can also follow us on Facebook and Twitter!
How to Get Current Page Name in WordPress
5 (100%) 3 votes

(Visited 293 times, 1 visits today)

About the Author: Editorial Staff

Editorial Staff at the WPChandra is a team of WordPress experts writing about WordPress Tutorials, Themes, Plugins, Guides, Tricks and much more...

Leave a Reply

Your email address will not be published. Required fields are marked *