snipt

Ctrl+h for KB shortcuts

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-28T11:43:35
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

PHP

Activate featured image in posts with functions.php

<?php add_theme_support( 'post-thumbnails' ); ?>
https://snipt.net/embed/1093e82e824982901d0c3a822f3da061/
https://snipt.net/raw/1093e82e824982901d0c3a822f3da061/
1093e82e824982901d0c3a822f3da061
php
PHP
1
2016-09-16T08:07:34
True
False
False
Apr 19, 2013 at 07:53 AM
/api/public/snipt/59571/
activate-featured-image-in-posts-with-functionsphp
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</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 class="nx">add_theme_support</span><span class="p">(</span> <span class="s1">&#39;post-thumbnails&#39;</span> <span class="p">);</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"featured image", wordpress

PHP

Print the link of the featured image

<?php if ( has_post_thumbnail()) {$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');echo $large_image_url[0];} ?>
https://snipt.net/embed/0e736342ce812b3c6adea315bcac2249/
https://snipt.net/raw/0e736342ce812b3c6adea315bcac2249/
0e736342ce812b3c6adea315bcac2249
php
PHP
1
2016-09-21T20:12:55
True
False
False
/api/public/snipt/42421/
print-the-link-of-the-featured-image
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</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 class="k">if</span> <span class="p">(</span> <span class="nx">has_post_thumbnail</span><span class="p">())</span> <span class="p">{</span><span class="nv">$large_image_url</span> <span class="o">=</span> <span class="nx">wp_get_attachment_image_src</span><span class="p">(</span> <span class="nx">get_post_thumbnail_id</span><span class="p">(),</span> <span class="s1">&#39;full&#39;</span><span class="p">);</span><span class="k">echo</span> <span class="nv">$large_image_url</span><span class="p">[</span><span class="mi">0</span><span class="p">];}</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"featured image", wordpress

CSS

Embed feature image as background CSS

style="background:url('<?php echo $feature_img_url[0]; ?>') no-repeat "
https://snipt.net/embed/0758698c00612d81ca8b37d15d0bdb42/
https://snipt.net/raw/0758698c00612d81ca8b37d15d0bdb42/
0758698c00612d81ca8b37d15d0bdb42
css
CSS
1
2016-09-21T13:31:53
True
False
False
Dec 12, 2012 at 03:18 PM
/api/public/snipt/41989/
embed-feature-image-as-background-css
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nt">style</span><span class="o">=</span><span class="s2">&quot;background:url(&#39;&lt;?php echo $feature_img_url[0]; ?&gt;&#39;) no-repeat &quot;</span> </span></pre></div> </td></tr></table>
"featured image", css, wordpress

PHP

Return URL only of Feature Image (post_thumbnail)

<?php echo wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); ?>
https://snipt.net/embed/6d2bb8e0cdd51a3c58ef74f2997b9867/
https://snipt.net/raw/6d2bb8e0cdd51a3c58ef74f2997b9867/
6d2bb8e0cdd51a3c58ef74f2997b9867
php
PHP
1
2016-09-21T17:40:52
True
False
False
Dec 12, 2012 at 03:18 PM
/api/public/snipt/41951/
return-url-only-of-feature-image-post_thumbnail
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</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 class="k">echo</span> <span class="nx">wp_get_attachment_url</span><span class="p">(</span> <span class="nx">get_post_thumbnail_id</span><span class="p">(</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">ID</span> <span class="p">)</span> <span class="p">);</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"featured image", "post thumbnail", wordpress
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.