snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#26418

PHP

remove image height and width for responsive design in WP

1
2
3
4
5
6
7
8
9
//remove inline width and height added to images
	add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
	add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
	// Removes attached image sizes as well
	add_filter( 'the_content', 'remove_thumbnail_dimensions', 10 );
	function remove_thumbnail_dimensions( $html ) {
    		$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    		return $html;
	}
https://snipt.net/embed/0b3c80100e559ec138ce635ada6d4773/
https://snipt.net/raw/0b3c80100e559ec138ce635ada6d4773/
0b3c80100e559ec138ce635ada6d4773
php
PHP
10
2014-04-23T18:50:22
True
False
/api/public/snipt/26418/
remove-image-height-and-width-for-responsive-design-in-wp
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">//remove inline width and height added to images</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> add_filter( &#39;post_thumbnail_html&#39;, &#39;remove_thumbnail_dimensions&#39;, 10 );</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> add_filter( &#39;image_send_to_editor&#39;, &#39;remove_thumbnail_dimensions&#39;, 10 );</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> // Removes attached image sizes as well</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> add_filter( &#39;the_content&#39;, &#39;remove_thumbnail_dimensions&#39;, 10 );</span> </span><span id="L-6"><a name="L-6"></a><span class="x"> function remove_thumbnail_dimensions( $html ) {</span> </span><span id="L-7"><a name="L-7"></a><span class="x"> $html = preg_replace( &#39;/(width|height)=\&quot;\d*\&quot;\s/&#39;, &quot;&quot;, $html );</span> </span><span id="L-8"><a name="L-8"></a><span class="x"> return $html;</span> </span><span id="L-9"><a name="L-9"></a><span class="x"> }</span> </span></pre></div> </td></tr></table>
"responsive design", functions, images, wordpress