Access post, page, category and author information in custom template page or embedded PHP script within WordPress

In a custom page you call as a template in WordPress, this is the standard way to access some of the information about the particular post or page being viewed.  This is possible by accessing the WordPress query object, which is already instantiated by WordPress in a global class called $wp_query.  There is much more information you can get from this object, by visiting  Another interesting aspect of accessing the $wp_query object is that you can override many of the properties and methods within this class to alter the functions, data, and output of the containing page so you can tailor the page for further customization.




$url= $url_arr['request_uri']=$_SERVER['REQUEST_URI'];

echo “Pagename: $pagename / Cat: $category_name / Url: $url / Author: $post_author”;

echo $html;

For custom pages, do not ever close your files with closing PHP tags with scripts. Please note that different WordPress themes like Genesis may have different functions that will either alter how you can access the $wp_query object and in some instances do not allow accessing it.

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

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