Wordpress Text Widget replaces php tags with html comment tags?

泪湿孤枕 提交于 2019-12-12 00:55:44

问题


I am attempting to add some php to a page on my wordpress site in the code editor part of my tiny mce editor. However, whenever type something like:

<?php echo "Hello World"; ?>

and then save the article, when I next go to edit the article it replaces my php tags with a html comment:

<!--?php echo "Hello World"; ?-->

Would be very grateful if anyone knows what is going on here and why WordPress is doing this.


回答1:


To use PHP code in your content editor, you will either need to install a plugin that allows you to do this, or create a shortcode.

To create a shortcode in functions.php:

<?php
function hello_shortcode() {
    echo 'Hello world!';
}
add_shortcode('hello', 'hello_shortcode');
?>

Then in the content editor, put:

[hello]

Hope this helps.



来源:https://stackoverflow.com/questions/50353211/wordpress-text-widget-replaces-php-tags-with-html-comment-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!