user317474
user317474

Reputation:

Execute PHP in WordPress

I need to run some code in every WordPress article.

The problem is, by default, WordPress does not execute any PHP in posts. I've tried a wealth of plugins (including ExecPHP and suchlike) but to no avail. How can I get PHP to run in WordPress?

Upvotes: 2

Views: 5753

Answers (5)

tutoground
tutoground

Reputation: 96

You can use "PHP Code for posts" plugin for this, after enable this plugin you will be able to run php code in wordpress editor like any php editor to run your php code you must write your code in php tags. you can download this plugin from here

https://wordpress.org/plugins/php-code-for-posts/

Upvotes: 0

williamvicary
williamvicary

Reputation: 805

This plugin will save you the hassle of having to make separate custom plugins:

http://www.hitreach.co.uk/wordpress-plugins/allow-php-in-posts-and-pages/

However as others have suggested this does potentially open security exploits as it's likely this code will utilise eval()

Upvotes: -1

hakre
hakre

Reputation: 198117

Goes like this:

Done.

Upvotes: 2

Luc Laverdure
Luc Laverdure

Reputation: 1480

This is dangerous as it can crash your entire site if it's not secured properly, but you may use the php function eval() to execute php code.

See:

http://ca.php.net/manual/en/function.eval.php

Upvotes: 2

clem
clem

Reputation: 3366

is it the same code for every article? if so why don't you change the wordpress file that creates the post and add the code in there?

Upvotes: 2

Related Questions