snipt

Ctrl+h for KB shortcuts

Text only

Utiliser PHP dans les widgets texte de WordPress

function php_text($text) {
 if (strpos($text, '<' . '?') !== false) {
 ob_start();
 eval('?' . '>' . $text);
 $text = ob_get_contents();
 ob_end_clean();
 }
 return $text;
}
add_filter('widget_text', 'php_text', 99);
https://snipt.net/embed/2586cdd3b67b6eec2346ecd91c3f750d/
/raw/2586cdd3b67b6eec2346ecd91c3f750d/
2586cdd3b67b6eec2346ecd91c3f750d
text
Text only
10
2019-08-24T01:42:47
True
False
False
Nov 13, 2012 at 04:26 PM
/api/public/snipt/50167/
utiliser-php-dans-les-widgets-texte-de-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> <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></span><span id="L-1"><a name="L-1"></a>function php_text($text) { </span><span id="L-2"><a name="L-2"></a> if (strpos($text, &#39;&lt;&#39; . &#39;?&#39;) !== false) { </span><span id="L-3"><a name="L-3"></a> ob_start(); </span><span id="L-4"><a name="L-4"></a> eval(&#39;?&#39; . &#39;&gt;&#39; . $text); </span><span id="L-5"><a name="L-5"></a> $text = ob_get_contents(); </span><span id="L-6"><a name="L-6"></a> ob_end_clean(); </span><span id="L-7"><a name="L-7"></a> } </span><span id="L-8"><a name="L-8"></a> return $text; </span><span id="L-9"><a name="L-9"></a>} </span><span id="L-10"><a name="L-10"></a>add_filter(&#39;widget_text&#39;, &#39;php_text&#39;, 99); </span></pre></div> </td></tr></table>
php, wordpress