snipt

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

PHP

custom more link

<?php

add_filter( 'the_content_more_link', 'my_more_link', 10, 2 );
$category = get_the_category(); echo $category[0]->cat_ID;

function my_more_link( $more_link, $more_link_text ) {
	return str_replace( $more_link_text, 'Continue reading &rarr;', $more_link );
}

?>
https://snipt.net/embed/c056f0ae32be73c28fad0769c1a3eda5/
https://snipt.net/raw/c056f0ae32be73c28fad0769c1a3eda5/
c056f0ae32be73c28fad0769c1a3eda5
php
PHP
10
2014-04-25T04:50:12
True
False
/api/public/snipt/6780/
custom-more-link
<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> <a href="#L-10">10</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><span id="L-3"><a name="L-3"></a><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;the_content_more_link&#39;</span><span class="p">,</span> <span class="s1">&#39;my_more_link&#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">2</span> <span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$category</span> <span class="o">=</span> <span class="nx">get_the_category</span><span class="p">();</span> <span class="k">echo</span> <span class="nv">$category</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-&gt;</span><span class="na">cat_ID</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="k">function</span> <span class="nf">my_more_link</span><span class="p">(</span> <span class="nv">$more_link</span><span class="p">,</span> <span class="nv">$more_link_text</span> <span class="p">)</span> <span class="p">{</span> </span><span id="L-7"><a name="L-7"></a> <span class="k">return</span> <span class="nb">str_replace</span><span class="p">(</span> <span class="nv">$more_link_text</span><span class="p">,</span> <span class="s1">&#39;Continue reading &amp;rarr;&#39;</span><span class="p">,</span> <span class="nv">$more_link</span> <span class="p">);</span> </span><span id="L-8"><a name="L-8"></a><span class="p">}</span> </span><span id="L-9"><a name="L-9"></a> </span><span id="L-10"><a name="L-10"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
wordpress