简体   繁体   中英

Wordpress Text Widget replaces php tags with html comment tags?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM