Support » Themes and Templates » Which template page is being used?

  • Hello, a simple question for somebody but not for me:

    developing a template I would like to show in the footer
    (for debugging use) the .php page name it’s currently
    being loaded from WP

    I know I can use a series of “if” and Conditional Tags
    but the question is if it’s possible to use a simpler
    function, something like
    (in my dreams)


Viewing 5 replies - 1 through 5 (of 5 total)
  • try:

    <?php $page_id = $wp_query->get_queried_object_id();
    echo get_post_meta( $page_id, '_wp_page_template', true ); ?>

    (extracted from:
    lines 426 and 441)

    Are you sure about this?
    I can’t echoing anything from this function…I’m using WP 3.0.1

    Please take a look at the bottom of the page between

    this is the code:
    <div id=”credits”>
    <div id=”ftnav”><span class=”rss”>” title=”<?php _e(‘Subscribe to RSS’); ?>” rel=”nofollow”><?php _e(‘<abbr title=”Subscribe to RSS”>RSS</abbr>’); ?></span></div>
    <small>Copyright © <?php echo date(“Y”); ?> <?php bloginfo(‘name’); ?> All rights reserved.
      [<?php echo get_num_queries(); ?> query – <?php timer_stop(1); ?> secondi]</small>.

    <?php $page_id = $wp_query->get_queried_object_id();
    echo get_post_meta( $page_id, ‘_wp_page_template’, true ); ?>

    <?php wp_footer(); ?>

    it will only show if you are on a page or page template, as in
    (a ‘normal’ page will show ‘default’)
    it does not show the template file names, such as index.php, category.pgp, or so.

    click on ‘cerca’ for instance – it will show ‘searchpage.php’ at the bottom.

    (if it is just for debugging, you could simply add
    <?php body_class(); ?>
    after the other code or instead – that would also give you some information about what templates are getting used)

    Ok, I thank you very much, as I can understand
    _wp_page_template is not used for post or archive pages

    this is a good point of start for me, but I’ll continue to search a (simple) trick to show the real template page used by WP.

    WordPress uses a variable $template to store the template being used. Therefore, for debugging (not recommended for a live site), you can put this in your theme’s functions.php:

    add_action('wp_head', 'show_template');
    function show_template() {
    	global $template;
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Which template page is being used?’ is closed to new replies.