Before I had the following code in the function.php

function execute_php($html){
     return $html;

Then I have updated WP to the version 4.4.1 and now it's not working anymore. Is there any other solution?

  • 1
    write you own widget that does what you need? This code you show is just a horrible idea. Jan 23, 2016 at 17:34
  • 1
    Yeah, I agree with Mark. This really is a bad idea. You should in theory be able to write a widget that would execute PHP safely, but one mistake and your site is compromised. And, honestly, if you are asking how to do this you don't have the knowledge to do it safely.
    – s_ha_dum
    Jan 23, 2016 at 19:16

2 Answers 2


Better to write your own widget that does precisely what you need instead of something like this.

However, if you really want to execute arbitrary PHP in a widget, use a plugin specifically designed for that task: https://wordpress.org/plugins/php-code-widget/

I maintain this plugin specifically so that people don't resort to doing things like what you have in your post. The PHP Code Widget is basically a copy of the text widget, but which also runs PHP Code.

Nevertheless, PHP Code Widgets are a bad-idea™ and should be avoided. Make a custom widget with your static code instead.

  • with 100k active installs seems like your appeal to only short term use it, is ignored by too many users :( Jan 23, 2016 at 18:10
  • Mark, to you, 100k is a lot. To me, it's down from 400k years ago, and I'm concerned with millions of sites. I'm happy in my progress. ;)
    – Otto
    Jan 30, 2016 at 0:52

I have faced the same problem, what I have noted is, professionally it is not advised to use plugin or functions.php for executing php in widgets, that's why such as now that functions.php technic don't work.

It is advised to construct your own widget, this is what I'm going to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.