snipt

Ctrl+h for KB shortcuts

PHP

Show which template is being used for the post/page you are viewing (in the admin Bar)

add_action( 'wp_head', 'show_me_the_template' );
function show_me_the_template() {
	global $template, $current_user, $wp_admin_bar;
	
	get_currentuserinfo();
        /* If you have more than one user deny. Be sure to use your user ID! */
	if ( !is_user_logged_in() && $current_user->ID != '1' ) 
		return;
	if ( is_admin_bar_showing() )
		$wp_admin_bar->add_menu( array(
			'parent' => false,
			'id' => 'template',
			'title' => $template,
			'href' => '#'
		));
	else
		print_r( $template );
}
https://snipt.net/embed/9ae387bfda4073ca05b9954ec8ed332d/
/raw/9ae387bfda4073ca05b9954ec8ed332d/
9ae387bfda4073ca05b9954ec8ed332d
php
PHP
18
2019-06-26T12:09:29
True
False
False
Oct 03, 2012 at 02:23 PM
/api/public/snipt/47998/
show-which-template-is-being-used-for-the-postpage-you-are-viewing-in-the-admin-bar
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a> <a href="#L-16">16</a> <a href="#L-17">17</a> <a href="#L-18">18</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">add_action( &#39;wp_head&#39;, &#39;show_me_the_template&#39; );</span> </span><span id="L-2"><a name="L-2"></a><span class="x">function show_me_the_template() {</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> global $template, $current_user, $wp_admin_bar;</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> </span> </span><span id="L-5"><a name="L-5"></a><span class="x"> get_currentuserinfo();</span> </span><span id="L-6"><a name="L-6"></a><span class="x"> /* If you have more than one user deny. Be sure to use your user ID! */</span> </span><span id="L-7"><a name="L-7"></a><span class="x"> if ( !is_user_logged_in() &amp;&amp; $current_user-&gt;ID != &#39;1&#39; ) </span> </span><span id="L-8"><a name="L-8"></a><span class="x"> return;</span> </span><span id="L-9"><a name="L-9"></a><span class="x"> if ( is_admin_bar_showing() )</span> </span><span id="L-10"><a name="L-10"></a><span class="x"> $wp_admin_bar-&gt;add_menu( array(</span> </span><span id="L-11"><a name="L-11"></a><span class="x"> &#39;parent&#39; =&gt; false,</span> </span><span id="L-12"><a name="L-12"></a><span class="x"> &#39;id&#39; =&gt; &#39;template&#39;,</span> </span><span id="L-13"><a name="L-13"></a><span class="x"> &#39;title&#39; =&gt; $template,</span> </span><span id="L-14"><a name="L-14"></a><span class="x"> &#39;href&#39; =&gt; &#39;#&#39;</span> </span><span id="L-15"><a name="L-15"></a><span class="x"> ));</span> </span><span id="L-16"><a name="L-16"></a><span class="x"> else</span> </span><span id="L-17"><a name="L-17"></a><span class="x"> print_r( $template );</span> </span><span id="L-18"><a name="L-18"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
admin, admin-bar, function, template, wordpress