This blog post will help you get current page name in WordPress. So if you are planning to create a WordPress plugin or want to fetch the current page then this simple code will be of great help.
$pagename
var if you use permalinks. It is because if you don’t use them, WP doesn’t need the page slug, so it doesn’t set it up.$pagename
in the file wp-includes/theme.php
, inside the function get_page_template()get_page_template()
the function is called before page theme files are parsed, so it is available at any point inside the templates for pages.Use the following code to get current page name in WordPress websites:
$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 = $absa_query->get_queried_object(); $pagename = $post->post_name; }
This code works fine if done properly. But still, if you are unable to get current page name in WordPress then Request a Quote. Our WordPress support staff will be in touch with you within minutes and assist you.
Apart from offering WordPress services and support, we also accept HTML to WordPress template conversion requests.