How to Execute php code in WordPress text widget

Add Tool

Execute php code in WordPress widget


WordPress widgets area is an important element to design a web site. You can display your site’s related post, recent post, random post and other what you want to display using WordPress widgets area. In these Web developer resources, I will share a simple WordPress snippet that will help to Execute php code in WordPress text widget.

Simply add the below WordPress snippet in your theme’s functions.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;
}

After adding this WordPress snippet your default WordPress text widgets will support PHP codes.

PHP enable WordPress text widgets

To test PHP codes in WordPress widgets area simply add some PHP codes in your WordPress default text widgets and see the result. You can try the following sample of php codes in WordPress text widgets.

<?php
 //Gets the IP address
 $ip = getenv("REMOTE_ADDR") ;
 Echo "Your IP is: " . '<b><span>'.$ip .'</span></b>';
 ?>

This code will display your IP address Where you place Your widgets it may be sidebar or footer area.


Tags: functions.php, IP address, Php, Snippet, Snippets, theme development, Website, WordPress, wordpress widgets, Execute php code, php run file
Payza

About Masum Billah

Execute php code in WordPress widget 1stWebSuite website seo tool is a free website ranking tool site provides a lot of on page and off page seo useful tools for you. On this site, we have a large number of website ranking tools


SIGN UP TO GET UPDATE TO YOUR INBOX




Discuss about: How to Execute php code in WordPress text widget


adf.ly