snipt

Ctrl+h for KB shortcuts

PHP

Get current page in WordPress admin

1
2
3
4
5
<?php
$current_screen = get_current_screen();
if ($current_screen->id === 'plugins') {
// http://codex.wordpress.org/Plugin_API/Admin_Screen_Reference
}
https://snipt.net/embed/6ebcd5ed617384a8fe068f24a6d354b9/
https://snipt.net/raw/6ebcd5ed617384a8fe068f24a6d354b9/
6ebcd5ed617384a8fe068f24a6d354b9
php
PHP
5
2016-09-24T14:07:31
True
False
False
Jun 16, 2016 at 08:46 AM
/api/public/snipt/147210/
get-current-page-in-wordpress-admin
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$current_screen</span> <span class="o">=</span> <span class="nx">get_current_screen</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a><span class="k">if</span> <span class="p">(</span><span class="nv">$current_screen</span><span class="o">-&gt;</span><span class="na">id</span> <span class="o">===</span> <span class="s1">&#39;plugins&#39;</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a><span class="c1">// http://codex.wordpress.org/Plugin_API/Admin_Screen_Reference</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
admin, dashboard, wordpress

PHP

Remove taxonomy metabox

1
2
3
4
5
<?php
function remove_custom_taxonomy() {
    remove_meta_box('tax_slugdiv', 'post_type_slug', 'side' );
}
add_action('admin_menu', 'remove_custom_taxonomy');
https://snipt.net/embed/58d71ebf1d0d7d0223f3d7fd58cb8a06/
https://snipt.net/raw/58d71ebf1d0d7d0223f3d7fd58cb8a06/
58d71ebf1d0d7d0223f3d7fd58cb8a06
php
PHP
5
2016-09-21T15:17:45
True
False
False
/api/public/snipt/145046/
remove-taxonomy-metabox
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="k">function</span> <span class="nf">remove_custom_taxonomy</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">remove_meta_box</span><span class="p">(</span><span class="s1">&#39;tax_slugdiv&#39;</span><span class="p">,</span> <span class="s1">&#39;post_type_slug&#39;</span><span class="p">,</span> <span class="s1">&#39;side&#39;</span> <span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span><span id="L-5"><a name="L-5"></a><span class="nx">add_action</span><span class="p">(</span><span class="s1">&#39;admin_menu&#39;</span><span class="p">,</span> <span class="s1">&#39;remove_custom_taxonomy&#39;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
admin, metabox, taxonomies

PHP

Add custom text to Featured Image meta box

1
2
3
4
5
<?php
function add_featured_image_instruction( $content ) {
    return $content .= '<p>Image will be automatically cropped to 640 x 328 pixels. You may crop your image to these dimensions before uploading for specific framing.</p>';
}
add_filter( 'admin_post_thumbnail_html', 'add_featured_image_instruction');
https://snipt.net/embed/06733c6a09213dfa370bfe2d3c626c6a/
https://snipt.net/raw/06733c6a09213dfa370bfe2d3c626c6a/
06733c6a09213dfa370bfe2d3c626c6a
php
PHP
6
2016-09-21T15:18:22
True
False
False
Feb 16, 2016 at 12:15 PM
/api/public/snipt/144287/
add-custom-text-to-featured-image-meta-box
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="k">function</span> <span class="nf">add_featured_image_instruction</span><span class="p">(</span> <span class="nv">$content</span> <span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="nv">$content</span> <span class="o">.=</span> <span class="s1">&#39;&lt;p&gt;Image will be automatically cropped to 640 x 328 pixels. You may crop your image to these dimensions before uploading for specific framing.&lt;/p&gt;&#39;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span><span id="L-5"><a name="L-5"></a><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;admin_post_thumbnail_html&#39;</span><span class="p">,</span> <span class="s1">&#39;add_featured_image_instruction&#39;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
"featured image", admin, wordpress
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.