Execute PHP in Wordpress post, page and Widget Sidebar

Advertisement

If you are still struggling on how to insert PHP Codes inside particular blog post, page or a widget sidebar for execution; the following tutorial is for you.

Executing PHP codes in Wordpress Page/Post

Installation

  1. Download phpexec.txt
  2. Rename phpexec.txt to phpexec.php
  3. Upload to /wp-content/plugins/ directory
  4. Activate the plug-in from Wordpress administration menu

Usage

Anywhere in your post/pages where you want to execute a PHP Codes, insert <phpcode> before your php codes and </phpcode> your php codes.

<phpcode>
	<?php
		echo "Current date and time: ";
		echo date("l dS of F Y h:i:s A");
	?>
</phpcode>

Security

If you are running a blog with multiple users, you need to determine who can run this plug-in. Alter the settings in your Administration Menu. Options -> PHPExec

Executing PHP codes in Wordpress widget sidebar

Installation

  1. Download execphp.txt
  2. Rename execphp.txt to execphp.php
  3. Upload to /wp-content/plugins/ directory
  4. Activate the plug-in from Wordpress administration menu

Usage

This plug-in work like a normal text widget except that it allows execution of PHP Codes. You can create up to 9 instances of this widget.

Related Contents

Sponsors

Posted by hongkiat in Wordpress, Wordpress Plugin , at 02.18.07

Comments

  1. CincauHangus February 18th, 2007

    does it work with other wysiwyg editors like xinha4wp ?

    Reply
  2. hongkiat February 19th, 2007

    Hm, I don’t think it will work in any WYSIWYG textbox. What you put in WYSIWYG is what you will see for output.

    I’ve never used xinha4wp before, not really planning to use WYSIWYG to write my entries :)

    Reply
  3. CincauHangus February 19th, 2007

    what i meant was using a wysiwyg editer, switch to see the html coding, then add the code there. would it still work? because there’s some editors that will discard unrecognised tags when posted… therefore the code wouldnt work.

    aah. a html coder i see :P i’m somewhat in between. :P

    Reply
  4. hongkiat February 20th, 2007

    Yeah, that’s what i mean :) Me using the coding mode, the tag works fine.

    Reply
  5. Ashish Mohta February 20th, 2007

    I ad been using the plugins from long time.But never used them inside the post.I am not able to understand what i can run inside my post.

    Reply
  6. hongkiat February 26th, 2007

    One good example would be Alex King’s popularity content plugin where you need to put “Top X Popular Content” on your sidebar. It requires phpcode, there’s where this sidebar php-insert comes in handy :)

    Reply
  7. Thilak March 2nd, 2007

    I had been using this while i was on Wordpress 1.5.x, but does it work with Wordpress 2.1.1 now ??

    Reply
  8. hongkiat March 3rd, 2007

    I’m still on WP 2.1. Are you sure it will not work with WP2.1.1? Hmm, something I should put on check list before upgrading.

    Reply
  9. Antonie Potgieter March 3rd, 2007

    I’m using WP2.1.1 and it doesn’t seem to work.
    Is there an alternative method to this?

    Reply
  10. Steven Sashen March 4th, 2007

    I’m using 2.1.1 and I can’t get it to work either… what I see is the php code (but note the tags)

    Am I doing something wrong?

    Reply
  11. hongkiat March 4th, 2007

    It is working for Wordpress 2.1.0 but however I noticed few saying its not working for Wordpress 2.1.1. I’ll update here once the authors have updated their plugins.

    Reply
  12. royalblogger March 14th, 2007

    Same here, not working with 2.1.1.

    Reply
  13. Gary Speer April 9th, 2007

    Anybody found out more about getting the execphp widget to work in WordPress 2.1.3?

    I can’t get it to do anything but display the php code or give me an error related to line 24, I think it is.

    Any help? Hope? (grin)

    Reply
  14. stephen April 12th, 2007

    i haven’t tested this yet, but for you 2.x.x+ users, try out this link here

    http://activeblogging.com/info/phpexec-2/

    Reply
  15. blogger tools April 22nd, 2007

    Exactly what I was looking for.
    I need to include a php script in my pages.
    I hope this plugin will be updated for the latest and coming versions of wordpress.

    and thanks for making life easier for us wordpress bloggers ;)

    Reply
  16. nazlihaffiz May 6th, 2007

    i’m using 2.1.3 in my other website at http://www.drnazlihaffiz.com and found that phpexec wasn’t working.

    the fact is it is working, only that you don’t have to type and all that. just put in your codings into the post but remember to edit the post in the code tab (not visual).

    hope this helps.

    cheers ;)

    Reply
  17. Ted July 8th, 2007

    Thanks, worked a treat.

    Reply
  18. Patu July 29th, 2007

    Hi, phpexec-2 dont work with wp 2.2.1 :(

    Help!!!

    Reply
  19. sealinda December 3rd, 2007

    Thanks so much for these codes, they are the way out for me!!! thanks!

    Reply
  20. Dan Kelly December 14th, 2007

    I love the simplicity of your script…

    It would be better if it actually worked for me. :-(

    I’m using the latest version of WordPress - 2.3.x.

    And, when I use the “Code” tab (even when I turn the visual editor off) and ender the following:

    In my post, I see:

    Any ideas on how to get it to work with wp v2.3.x?

    Thanks!!

    Reply
  21. Sherry March 3rd, 2008

    Thank you so much for this. I was going nuts trying to find out how to get php to work in my custom plug-ins. Your code is essential, in my opinion! I will definitely support your site and will be back in the future.

    Reply
  22. Alfie May 12th, 2008

    Will it work on WP 2.5?

    Reply
  23. AntonJamm May 13th, 2008

    Unable to get working on v2.5, looking at RunPHP right now

    Reply
  24. Judah Mu June 5th, 2008

    Is php’s:
    include_once (’/myOther.php’); supported in pages and posts? Can’t seem to get it working… Other php functionality is working on WP2.1.2

    Reply
  25. Steven June 24th, 2008

    My phpcode function stopped working!! It was working perfect on WP 2.5.1 :(

    I deactivated all plugins but phpexec, re-uploaded the script but nothing seems to help.. code is visible in posts :( Managing pages was saved in HTML-view. I host my own WP so have full control. What else can I try? Really need help on this.

    Reply
  26. paul mall June 26th, 2008

    I have had some bugs in zended php files that prevented my site from running properly.

    I finally found a program that can decompile the zended script. The website is for site owners who have lost their source code.

    http://www.decode-zend-decoder.com

    Hope this helps someone who is stuck like I was.

    Reply
  27. Mario August 16th, 2008

    Hello, not working at all for me with the following query in wp 2.5.1

    posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE $wpdb->postmeta.meta_value = 'Arezzo'
    ORDER BY $wpdb->postmeta.meta_value ASC
    ";

    $pageposts = $wpdb->get_results($querystr, OBJECT);

    ?>

    <div class="post" id="post-">
    <a href="" rel="bookmark" title="Permanent Link to ">

    Sorry, but you are looking for something that isn’t here.

    Any idea?? Thanks

    Reply
  28. Mario August 16th, 2008

    Mmmmhhh the code in my prev comment got cut out…hope you get the whole deal on the admin side

    Reply
  29. Pinara.Net August 29th, 2008

    That plugin is save?

    Reply
  30. Jas September 5th, 2008

    Amazing Plugin and want to let you know its working with Wordpress 2.6 Also :)

    Reply
  31. Jas September 5th, 2008

    Hi,

    :( It was running from my cache, but got a nice solution! Chec this:
    http://www.free-mobile-4u.co.uk/wp-content/plugins/exec-php/docs/readme.html#tag_balancing

    Reply
  32. Danno September 17th, 2008

    Excellent plugin. Thanks so much. Workin’ just fine here on 2.6.2.

    Reply
  33. Larry Bradshaw September 19th, 2008

    I tried this and still got nothing but text on my page.

    Reply
  34. Maclin September 25th, 2008

    hi,
    its good site

    Reply
  35. Steve Rial October 3rd, 2008

    It worked absolutely perfectly and was exactly what I needed. Thanks for the good work.

    Reply

Leave a reply