Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of running PHP code in WordPress text gadget

Shulou Source: shulou.com Published: 2022-06-02 05:35:52 09月12日 Update

This article is about how to run PHP code in WordPress text gadgets. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

WordPress text gadget can add arbitrary HTML code, but the default PHP code added to the text gadget does not run, the following code is very useful!

Add the following code to the functions.php file for your current theme:

Add_filter ('widget_text',' php_text', 99); function php_text ($text) {if (strpos ($text,''. $text); $text = ob_get_contents (); ob_end_clean ();} return $text;}

After that, you can add a text gadget to the sidebar and enter the PHP function code into it to see if it works.

Previously recommended plug-in: MO Widgets can run PHP in a gadget, but the above code is more convenient and practical.

Thank you for reading! This is the way to run PHP code in the WordPress text gadget. I hope the above can be helpful to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Tags: Code tools text run method utility content more good theme side function plug-in file article useful see knowledge article face Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Xiaomi Huawei Docker Microsoft