Wordpress Text Widget用html注释标签替换php标签?

问题描述:

我试图在我的小型mce编辑器的代码编辑器部分的wordpress网站上的页面上添加一些php。但是,只要键入以下内容:

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"; ?>

然后保存文章,当我下次去编辑文章时,它将php标签替换为html注释:

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"; ?-->

如果有人知道这里发生了什么以及WordPress为什么这样做,将不胜感激。

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

要在内容编辑器中使用PHP代码,您将需要安装允许您执行此操作的插件,或者创建一个

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.

要在functions.php中创建简码:

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]

希望这会有所帮助。