PHP Tricks

Execute PHP Code in Text Widgets

Execute PHP Code in Text Widgets

Execute PHP code in text widgets. By the default, text Widget in WordPress allows only writing text. And There is some plugins directory in the official WordPress widgets that allows you to add PHP inside a widget. Alternatively, you can use that snippet of code to allow PHP code to be executed.

File to edit: functions.php

 

[box type=”shadow” align=”aligncenter” class=”” width=””]

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);

[/box]

 

By this code you can Execute PHP code in text widgets.

 

Leave a Reply