Reputation: 989
I'm trying to add a php code inside a custom HTML widget but the site in showing this like plain text.
Any idea why is this happening?
PHP CODE:
<?php
$param = uniqid();
echo "<script language='javascript'>";
echo "alert('message successfully sent ' . $param)";
echo "</script>";
?>
HTML:
HOW I SEE THE PAGE:
Upvotes: 4
Views: 6119
Reputation: 670
Same problem happenned to me today!!, resolved it by adding the following code to the Wordpress theme function.php file.
add_filter('widget_text','execute_php',100);
function execute_php($html){
if(strpos($html,"<"."?php")!==false){
ob_start();
eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}
To enable shortcodes in the Text and Custom HTML widget just add this code to your theme functions.php :
add_filter('widget_text','do_shortcode',10);
Upvotes: 2