Techniqued- Technoloy, Review and Tutorials
  • Android
  • Freewares
  • Tutorial
  • Windows 11
  • macOS
No Result
View All Result
Techniqued- Technoloy, Review and Tutorials
  • Android
  • Freewares
  • Tutorial
  • Windows 11
  • macOS
No Result
View All Result
Techniqued- Technoloy, Review and Tutorials
No Result
View All Result

How to Execute PHP in WordPress Text Widgets without any Plugins

Nirmal by Nirmal
November 7, 2012
in Wordpress
1
Share on FacebookShare on Twitter

WordPress is the most popular platform when it comes to blogging with tons of features and tons of themes and plugins to customize it. WordPress also has widgets in themes which allows you to easily display content in sidebar or locations where widgets are supported. The most commonly used widget is text widget, you can enter any HTML text and it will display without any issues. But at the same time, one of the main problems of widgets is that PHP code is not supported although you can use text, HTML and scripts.

wplogo-hoz-cmyk

There are many plugins which can bring in this feature to WordPress by adding a WordPress PHP widget, but there is a simpler way to enable this feature using a simple script suggested by Emanuele Feronato. To add php code to widgets, add the below function to functions.php file in your theme.

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

Open the functions.php file available in your WordPress theme and add this function, save the file. This will turn the default text widget into a php enabled widget. Here is an example;

Widget

Make sure you use the correct php formatting in the widget to make the content available online.

Detailed explanation on how this function works is available here. This function is pretty handy as you do not have to increase the server load by installing another plugin to get the php functionality.

Tags: PHP SupportTipsTutorialsWidgetsWordpress
ShareTweetSendSend
Previous Post

Download Android 4.2 Core Apps for Galaxy Nexus

Next Post

How to Enable Flash on Any Website in IE10 Metro Browser

Related Posts

Wordpress

How To Fix “The Link You Followed Has Expired” Error in WordPress

December 9, 2020
Wordpress

Install WordPress Locally on Windows with Local

February 24, 2020
Windows 10

How to Create a Windows 10 App for WordPress Blog

March 21, 2016
Wordpress

7 Ways to Install WordPress Locally on Windows or Mac

January 9, 2015
Wordpress

5 Ways To Reduce Spam Comments Spam On WordPress

January 8, 2015
Wordpress

10 Best WordPress Backup Services for your Blog

January 5, 2015

Comments 1

  1. Paul says:
    12 years ago

    Bit risky using eval in the admin area of your site.

    I’ll rather create a shortcode for the user to use in widget which is easily done by a filter http://www.paulund.co.uk/enable-shortcodes-in-widgets

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.



Latest Articles

How to Fix “Installation can’t continue” when trying to Update Nvidia Graphics Drivers

Download Windows 11 24H2 ISO (Offline Installer)

Can I Run Windows 11 without Activating

How to Use Snapchat on PC

How to Delete YouTube Search and Watch History on iPhone

How to Use Energy Saver on Windows 11

Techniqued- Technoloy, Review and Tutorials

© 2021 Techniqued - Technology, Tips, Tricks and Reviews

Navigate Site

  • About Us
  • Advertise with us
  • Contact Us
  • Copyright Policy
  • Disclaimer

Follow Us

No Result
View All Result
  • Android
  • Freewares
  • Tutorial
  • Windows 11
  • macOS

© 2021 Techniqued - Technology, Tips, Tricks and Reviews

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.