Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

adds read more to excerpt

1
2
3
4
5
// excerpt read more links and wrap excerpt in p tag
function all_excerpts_get_more_link($post_excerpt) {
    return '<p>' . $post_excerpt . '</p>' . '<p class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>';
}
add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
https://snipt.net/embed/e87c94a34110ee11b3362ffea9098806/
https://snipt.net/raw/e87c94a34110ee11b3362ffea9098806/
e87c94a34110ee11b3362ffea9098806
php
PHP
5
2016-11-20T10:00:10
True
False
False
/api/public/snipt/27989/
adds-read-more-to-excerpt
<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></span><span id="L-1"><a name="L-1"></a><span class="x">// excerpt read more links and wrap excerpt in p tag</span> </span><span id="L-2"><a name="L-2"></a><span class="x">function all_excerpts_get_more_link($post_excerpt) {</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> return &#39;&lt;p&gt;&#39; . $post_excerpt . &#39;&lt;/p&gt;&#39; . &#39;&lt;p class=&quot;readmore&quot;&gt;&lt;a href=&quot;&#39;. get_permalink($post-&gt;ID) . &#39;&quot;&gt;&#39; . &#39;Continue Reading &amp;raquo&#39; . &#39;&lt;/a&gt;&lt;/p&gt;&#39;;</span> </span><span id="L-4"><a name="L-4"></a><span class="x">}</span> </span><span id="L-5"><a name="L-5"></a><span class="x">add_filter(&#39;wp_trim_excerpt&#39;, &#39;all_excerpts_get_more_link&#39;);</span> </span></pre></div> </td></tr></table>
excerpt, php, wordpress

PHP

Excerpt length in WordPress

1
2
3
4
5
6
<?php
function new_excerpt_length($length) {
	return 15;
}
add_filter('excerpt_length', 'new_excerpt_length');
?>
https://snipt.net/embed/b302a9e0a30eaac75c25a8b4b161bcb6/
https://snipt.net/raw/b302a9e0a30eaac75c25a8b4b161bcb6/
b302a9e0a30eaac75c25a8b4b161bcb6
php
PHP
6
2016-12-05T06:46:28
True
False
False
/api/public/snipt/22849/
excerpt-length-in-wordpress
<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">function</span> <span class="nf">new_excerpt_length</span><span class="p">(</span><span class="nv">$length</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="mi">15</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;excerpt_length&#39;</span><span class="p">,</span> <span class="s1">&#39;new_excerpt_length&#39;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
excerpt, filter, length, wordpress

PHP

remove default end chars of excerpt

1
2
3
4
5
/* REMOVE [...] from excerpt */
function new_excerpt_more($more) {
	return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');
https://snipt.net/embed/a61d133e3728d9d533cafaa3710382db/
https://snipt.net/raw/a61d133e3728d9d533cafaa3710382db/
a61d133e3728d9d533cafaa3710382db
php
PHP
5
2016-11-05T17:05:11
True
False
False
/api/public/snipt/22811/
remove-default-end-chars-of-excerpt
<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></span><span id="L-1"><a name="L-1"></a><span class="x">/* REMOVE [...] from excerpt */</span> </span><span id="L-2"><a name="L-2"></a><span class="x">function new_excerpt_more($more) {</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> return &#39;...&#39;;</span> </span><span id="L-4"><a name="L-4"></a><span class="x">}</span> </span><span id="L-5"><a name="L-5"></a><span class="x">add_filter(&#39;excerpt_more&#39;, &#39;new_excerpt_more&#39;);</span> </span></pre></div> </td></tr></table>
excerpt, php, wordpress

PHP

change default excerpt length if excerpt hasnt been set

1
2
3
4
5
/*CHANGE EXCERPT LENGTH*/
function new_excerpt_length($length) {
	return 40;
}
add_filter('excerpt_length', 'new_excerpt_length');
https://snipt.net/embed/4a106a17b3866ec84497c5596f2b402c/
https://snipt.net/raw/4a106a17b3866ec84497c5596f2b402c/
4a106a17b3866ec84497c5596f2b402c
php
PHP
5
2016-11-17T02:38:12
True
False
False
/api/public/snipt/22810/
change-default-excerpt-length-if-excerpt-hasnt-been-set
<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></span><span id="L-1"><a name="L-1"></a><span class="x">/*CHANGE EXCERPT LENGTH*/</span> </span><span id="L-2"><a name="L-2"></a><span class="x">function new_excerpt_length($length) {</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> return 40;</span> </span><span id="L-4"><a name="L-4"></a><span class="x">}</span> </span><span id="L-5"><a name="L-5"></a><span class="x">add_filter(&#39;excerpt_length&#39;, &#39;new_excerpt_length&#39;);</span> </span></pre></div> </td></tr></table>
excerpt, php, wordpress

PHP

Change the height of the excerpt field in WP-Admin

1
2
3
4
5
6
7
<?php
// excerpt height
function admin_excerpt() {
	echo "<style>"; echo "textarea#excerpt {height: 200px;}"; echo "</style>";
}
add_action('admin_head', 'admin_excerpt');
?>
https://snipt.net/embed/e8da786b65f7057ab62ebc8a6f534cde/
https://snipt.net/raw/e8da786b65f7057ab62ebc8a6f534cde/
e8da786b65f7057ab62ebc8a6f534cde
php
PHP
7
2016-12-04T11:42:33
True
False
False
/api/public/snipt/18762/
change-the-height-of-the-excerpt-field-in-wp-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> <a href="#L-6">6</a> <a href="#L-7">7</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="c1">// excerpt height</span> </span><span id="L-3"><a name="L-3"></a><span class="k">function</span> <span class="nf">admin_excerpt</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">echo</span> <span class="s2">&quot;&lt;style&gt;&quot;</span><span class="p">;</span> <span class="k">echo</span> <span class="s2">&quot;textarea#excerpt {height: 200px;}&quot;</span><span class="p">;</span> <span class="k">echo</span> <span class="s2">&quot;&lt;/style&gt;&quot;</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span><span id="L-6"><a name="L-6"></a><span class="nx">add_action</span><span class="p">(</span><span class="s1">&#39;admin_head&#39;</span><span class="p">,</span> <span class="s1">&#39;admin_excerpt&#39;</span><span class="p">);</span> </span><span id="L-7"><a name="L-7"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
excerpt, wordpress, wp-admin
Copyrighted, illegal, or inappropriate content? Email [email protected].