Last active
August 29, 2015 14:16
-
-
Save jerewall/81ffeecbce5ab764df7c to your computer and use it in GitHub Desktop.
How to execute PHP code in Text Widget without using Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Sometimes we need to execute PHP scripts in text widget but by default WordPress doesn’t allow this feature because of | |
security issues. | |
Find the functions.php file of your current theme and add the following code at the end of the file. | |
*/ | |
function php_execute($html){ | |
if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html); | |
$html=ob_get_contents(); | |
ob_end_clean(); | |
} | |
return $html; | |
} | |
add_filter('widget_text','php_execute',100); | |
// use [template_directory_uri] within the sidebar or posts. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment