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

Disclosure: This post contains affiliate links. This means we may make a small commission if you make a purchase. This doesn’t cost you any more but it does help us to continue publishing helpful content – thank you for your support!

How to Get Current Page Name in WordPress
5 (100%) 3 votes

(Visited 315 times, 1 visits today)

Leave a Comment

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