Rahul Sarkar
Rahul Sarkar

Reputation: 89

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

Upvotes: 0

Views: 707

Answers (2)

WeSee
WeSee

Reputation: 3762

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

Upvotes: 1

daniyalahmad
daniyalahmad

Reputation: 3843

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

Upvotes: 0

Related Questions