Print Current WordPress Template Being Used


/ Published in: PHP
Save to your folder(s)

Add this to the functions.php file. Make sure the Admin Bar is set to show when viewing site. You will see in the Admin Bar the current page template that is being used.


Copy this code and paste it in your HTML
  1. <?php
  2. add_action( 'wp_head', 'admin_print_template_used' );
  3. function admin_print_template_used() {
  4. global $template, $current_user, $wp_admin_bar;
  5. get_currentuserinfo();
  6. if ( !is_user_logged_in() && $current_user->ID != '1' )
  7. return;
  8. if ( is_admin_bar_showing() )
  9. $wp_admin_bar->add_menu( array(
  10. 'parent' => false,
  11. 'id' => 'template',
  12. 'title' => $template,
  13. 'href' => '#'
  14. ));
  15. else
  16. print_r( $template );
  17. }
  18. // START THE SCRIPT TO PUSH ADMIN BAR TO BOTTOM
  19. function fb_move_admin_bar() {
  20. echo '
  21. <style type="text/css">
  22. body {
  23. padding-bottom: 28px;
  24. }
  25. body.admin-bar #wphead {
  26. padding-top: 0;
  27. }
  28. body.admin-bar #footer {
  29. padding-bottom: 28px;
  30. }
  31. #wpadminbar {
  32. top: auto !important;
  33. bottom: 0;
  34. }
  35. #wpadminbar .quicklinks .menupop ul {
  36. bottom: 28px;
  37. }
  38. </style>';
  39. }
  40. // on backend area
  41. add_action( 'admin_head', 'fb_move_admin_bar' );
  42. // on frontend area
  43. add_action( 'wp_head', 'fb_move_admin_bar' );
  44. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.