jump to navigation

Execute PHP code in your WordPress posts , pages and text-widgets July 3, 2011

Posted by Tournas Dimitrios in Wordpress - 3.

WordPress , for security reasons , is very sensitive with external code . Even code snippets written in comment sections are “striped out” . Often an article must be supported by an code example to emphasis the functionality of the content of that article . I use an simple method to bypass the security restrictions of WordPress , just encapsulate the example code in code tags  [  sourcecode  language=” j a v a s c r i p t ”  ]  [  /  sourcecode  ] . If you realy like to use plug-ins , then tray  Google Syntax Highlighter for WordPress . This plugin makes using the Google Syntax highlighter by Alex Gorbatchev to highlight code snippets within WordPress simple .

By default WordPress doesn’t allow to execute PHP-code  from inside an post , page  or text-widget  . This WorPress plug-in ( Exec-PHP ) makes it possible to write and execute PHP – code directly into your posts , pages and text-widgets . Although many plug-ins provide the same functionality , Exec-PHP has an extensive documentation .

Just download and enable the plug-in ( unzip and transfer the “exec-php” folder in your WordPress installation ->  WordPress-Root\wp-content\plugins ) . You are ready to execute PHP code .

function hello()
  echo 'Hello World';

Read also : Writing code in your articles from Codex.wordpress.org


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s