snipt

Ctrl+h for KB shortcuts

HTML+PHP

Thumbnail Post (Featured image) / with default

1
2
3
4
5
6
<?php 
    if ( has_post_thumbnail() ) { 
  		the_post_thumbnail('defined size'); // define size of thumb
	} else { ?>	<!-- if don't exist use -->
		<img src="<?php bloginfo('template_url'); ?>/img/path/file.jpg">
<?php } ?>
https://snipt.net/embed/0f66290607c1f219f42057b3fbbc3788/
/raw/0f66290607c1f219f42057b3fbbc3788/
0f66290607c1f219f42057b3fbbc3788
html+php
HTML+PHP
6
2019-08-24T09:58:53
True
False
False
/api/public/snipt/42207/
thumbnail-post-featured-image-with-default
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><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">if</span> <span class="p">(</span> <span class="nx">has_post_thumbnail</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">the_post_thumbnail</span><span class="p">(</span><span class="s1">&#39;defined size&#39;</span><span class="p">);</span> <span class="c1">// define size of thumb</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="cp">?&gt;</span> <span class="c">&lt;!-- if don&#39;t exist use --&gt;</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">&lt;</span><span class="nt">img</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">&lt;?php</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;template_url&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="s">/img/path/file.jpg&quot;</span><span class="p">&gt;</span> </span><span id="L-6"><a name="L-6"></a><span class="cp">&lt;?php</span> <span class="p">}</span> <span class="cp">?&gt;</span> </span></pre></div> </td></tr></table>
"default image", featured, image, thumb, thumbnail, wordpress