snipt

Ctrl+h for KB shortcuts

HTML+PHP

trim

1
2
3
4
				<?php
				$excerpt = get_the_excerpt();
				$trimmed_content = wp_trim_words( $excerpt, 40, '<br /><a href="'. get_permalink() .'" class="link_excerpt"> ...leer más</a>' );
				echo $trimmed_content;?>
https://snipt.net/embed/63c7d5330af2939000354b0cf34a30f2/
https://snipt.net/raw/63c7d5330af2939000354b0cf34a30f2/
63c7d5330af2939000354b0cf34a30f2
html+php
HTML+PHP
4
2016-09-22T19:48:28
True
False
False
Nov 06, 2013 at 12:01 PM
/api/public/snipt/92211/
trim-5
<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></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">$excerpt</span> <span class="o">=</span> <span class="nx">get_the_excerpt</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$trimmed_content</span> <span class="o">=</span> <span class="nx">wp_trim_words</span><span class="p">(</span> <span class="nv">$excerpt</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="s1">&#39;&lt;br /&gt;&lt;a href=&quot;&#39;</span><span class="o">.</span> <span class="nx">get_permalink</span><span class="p">()</span> <span class="o">.</span><span class="s1">&#39;&quot; class=&quot;link_excerpt&quot;&gt; ...leer más&lt;/a&gt;&#39;</span> <span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">echo</span> <span class="nv">$trimmed_content</span><span class="p">;</span><span class="cp">?&gt;</span> </span></pre></div> </td></tr></table>
trim, wordpress

JavaScript

Limit string length/trim text with jQuery

1
2
3
4
5
6
7
8
jQuery(document).ready(function($){
	$("h3").each(function(){
	        if ($(this).text().length > 30) {
	            $(this).text($(this).text().substr(0, 27)); 
	            $(this).append('...');
	        }
	    });
});
https://snipt.net/embed/cff52cef5e9cd507cea011f043282c54/
https://snipt.net/raw/cff52cef5e9cd507cea011f043282c54/
cff52cef5e9cd507cea011f043282c54
js
JavaScript
8
2016-09-26T01:59:03
True
False
False
/api/public/snipt/43488/
limit-string-lengthtrim-text-with-jquery
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nx">jQuery</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">$</span><span class="p">){</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;h3&quot;</span><span class="p">).</span><span class="nx">each</span><span class="p">(</span><span class="kd">function</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="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">text</span><span class="p">().</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">30</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">text</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">text</span><span class="p">().</span><span class="nx">substr</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">27</span><span class="p">));</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">append</span><span class="p">(</span><span class="s1">&#39;...&#39;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">}</span> </span><span id="L-7"><a name="L-7"></a> <span class="p">});</span> </span><span id="L-8"><a name="L-8"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
javascript, jquery, length, limit, trim

JavaScript

Trim string to length

1
2
3
4
5
function trimLength(str, length) {
	str = $.trim(str); // jQuery required
	str = str.slice(0, length);
	return str;
}
https://snipt.net/embed/b282ce90eccedb80413e42bfea8f0572/
https://snipt.net/raw/b282ce90eccedb80413e42bfea8f0572/
b282ce90eccedb80413e42bfea8f0572
js
JavaScript
5
2016-09-27T00:35:13
True
False
False
/api/public/snipt/23868/
trim-string-to-length
<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="kd">function</span> <span class="nx">trimLength</span><span class="p">(</span><span class="nx">str</span><span class="p">,</span> <span class="nx">length</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">str</span> <span class="o">=</span> <span class="nx">$</span><span class="p">.</span><span class="nx">trim</span><span class="p">(</span><span class="nx">str</span><span class="p">);</span> <span class="c1">// jQuery required</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">str</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">length</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">return</span> <span class="nx">str</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
cut, function, helper, javascript, length, shorten, snippet, string, trim
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.