简体   繁体   中英

PHP code in wordpress page

I have a working wordpress theme. I don't have any plugins installed in my theme. When I created a new page and wrote PHP code to echo a single line, it does not show anything. I edit the wp_config file and set define('WP_DEBUG', false) to define('WP_DEBUG', true) ......but nothing happen, the code is below

 <?php
    echo 'gggggggggggggg';
    ?>

When inserting your PHP code into wordpress pages, there are two recommended ways:

  • make a child theme
  • write your own plugin

Making a child theme is faily easy and a common way for little PHP extensions.

There is also a plugin available to insert PHP code into pages here .

You should avoid to put PHP files into the internal Wordpress directories or modify wordpress files since these modifications get lost with updates which happen to be quite often in Wordpress

You cannot write PHP in pages directly and its not recommended to do so, because you are opening doors to world of security threats.

The best way to write is, by creating templates(wirte your PHP there) and then assign it to some page.

https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/#creating-custom-page-templates-for-global-use

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