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
  36. mommaroodles November 6th, 2008

    Hi
    Just wondering if you could help me with something please. I am a bit of a WP newbie and not too good with PHP. If I wanted to write a page and include a particular post from a category, how would I include that. I know that I would have to find the post ID but and have been trying a couple of edits, but am not getting it right. I’d be very happy if you could show me how its done, if it can be done!

    Rgds :)

    Reply
  37. Galwin December 12th, 2008

    Cool! I really helps!

    Reply
  38. Dave Hassen January 27th, 2009

    Doesn’t seem to work on 2.7.

    All I get in my post (using your sample php up there) is the markup displayed on the screen.

    Reply
  39. Alvyn K February 4th, 2009

    Well, I guess I had just found the answer to most your problems listed here.

    I tried execphp.php as well, but it didn’t work on WP 2.7. So I copied the whole of my php file (AC Image/Text Slider) into the “ad unit” under post. Import it as ad unit then insert into post / page.

    Wa lah! It appeared nice and fine.

    You can check it out here http://www.alvyncool.com

    Reply
  40. Amit Banerjee February 4th, 2009

    Doesn’t works for me Either……I am using Wp-2.7

    It would be Nice of you to fix the plugin for 2.7

    Thanks

    Reply
  41. Vacom February 7th, 2009

    Yahhh…same too me! Not work with Wp-2.7

    Reply
  42. Karl February 10th, 2009

    It works fine for me in the sidebar. After installing and activating the plugin, can add php code to the “Text” box in the sidebar and it works fine.

    Reply
  43. Link February 14th, 2009

    This plugin can execute PHP code only for registered user – administartor. But what I need to do for working it for non-registered users? If I have 5-10k users daily… I downloadd Role-Plugin – and can`t nothing to do.. Help :)

    Reply
  44. yo February 26th, 2009

    thanks a lot man. huge help. been lookin for this for a while

    Reply
  45. wheelf March 4th, 2009

    +1 к предыдущему комментарию

    Reply
  46. Anne March 5th, 2009

    amazingly easy !
    Thanks.

    Reply
  47. Arun Sukumar March 7th, 2009

    Hi Brother,
    Thanks for the plugin, Keep producing :)

    Reply
  48. Bayu Hendra Winata April 2nd, 2009

    works for me, thanks

    Reply
  49. MCA April 25th, 2009

    hi dude,
    this is awesome, thanks!

    Reply
  50. nuague April 27th, 2009

    Ага, теперь понятно…А то я сразу не очень то и не понял где тут связь с самим заголовком…

    Reply
  51. FafSceva May 14th, 2009

    Спасибо вам за сайт, очень полезный ресурс, мне очень нравится

    Reply
  52. вебмастеру May 26th, 2009

    Никогда не спорьте с умным: люди могут не заметить между вами разницы!

    Reply
  53. Treldbede May 27th, 2009

    Камрад убей себя=)

    Reply
  54. Treldbede May 27th, 2009

    Спасибочки:) Классная тема, пишите чаше – у вас отлично получается =)

    Reply
  55. Treldbede May 27th, 2009

    Как обычно, вебмастер грамотно опубликовал!=)

    Reply
  56. Treldbede May 27th, 2009

    Полностью с Вами согласна, примерно неделю назад написала про этоже в своем блоге!=)

    Reply
  57. Treldbede May 27th, 2009

    Приветики! Читаю не первый день странички. Да вот скорость соединения хромает. Как можно подписаться на вашу RSS-ленту? Хотел бы читать вас и дальше.:-)

    Reply
  58. Treldbede May 27th, 2009

    Я подписался на RSS ленту, но сообщения почему-то в виде каких-то иероглифов :( Как это исправить?!

    Reply
  59. форум фанов May 27th, 2009

    Недавно наткнулся на форум фанов, там действительно есть что почитать

    Reply
  60. срочный выкуп автомобиля May 29th, 2009

  61. интернет аукцион монет June 2nd, 2009

    До сих пор ищите где продать? Тогда специально для вас наше предложение – интернет аукцион Украины

    Reply
  62. озеленение June 2nd, 2009

    Заходи к нам и мы раскажем тебе про правильное озеленение

    Reply
  63. любовь June 2nd, 2009

    Очень важный момент в жизни каждого человека – это зачатие; )

    Reply
  64. здоровье June 2nd, 2009

    Отличный пост, но помните что здоровье важнее всего

    Reply
  65. отделка June 3rd, 2009

    В принципе интересные проекты

    Reply
  66. смотреть видео June 3rd, 2009

    Чем мельче интересы мужчины, тем крупнее кажется ему каждая мелочь.

    Reply
  67. oricluber June 6th, 2009

    oriclub

    Reply
  68. haungo June 26th, 2009

    Thanks! works awesome !

    Reply
  69. your ip address July 2nd, 2009

    Do you want know your see request variables – for free?

    Reply
  70. GEO base services July 2nd, 2009

    Cool servise – Trace ip tools

    Reply
  71. Mia July 9th, 2009

    I read your website every week, its great and got lots of information to take in and lots of interesting articles.

    Reply
  72. famous logos July 11th, 2009

    hmm..now this is some serious stuff. I hope that it will work with the latest version of WP

    Reply
  73. Custom iPod cases July 20th, 2009

    hummm its not working for me

    Reply
  74. Mike July 29th, 2009

    the plugin works fine (wp2.8) but if you switch out of HTML to visual the code gets deleted – is there anyway of preventing this from happening – or onvce the code is used you have to stay in HTML mode?

    great plugin.. when it works…

    Reply
  75. brother incest July 29th, 2009

    Interesting link just for you – mother son incest video

    Reply
  76. replica designer shoes August 1st, 2009

    Fine link for you – dooney and bourke knock offs

    Reply
  77. breitling emergency replica August 2nd, 2009

    Hey, you must see that – tady tag heuer watch replica

    Reply
  78. 7online August 7th, 2009

    технологии 7online про такое слыхали

    Reply
  79. download Microsoft Windows Home Server August 20th, 2009

  80. Jessica Rewnell August 22nd, 2009

    I seriously don’t understand how to get a wordpress sidebar!!!

    Reply
  81. Garcya August 31st, 2009

    Yep, the plugin from http://activeblogging.com/info/phpexec-2/ does work with Version 2.8.4 also.
    PS: doesn’t anybody delete those spam in comments?

    Reply
  82. webdesign September 2nd, 2009

    Wow it works for my new wordpress system i am building :) very nice thx
    Only i get errors wen i want to include :(

    Reply
  83. Nicole Thompsen September 11th, 2009

    Om du söker efter mest önskad klassiska och eleganta designer av replica Omega därefter, vår website är det bäst förlägger för att finna det.

    Reply
  84. peter September 14th, 2009

    Does your hardwood floors have wax build up and scratches?
    It is time to refinish them and make the hardwood look brand new again.
    Read more here:
    http://www.hardwoodfloor.x10hosting.com

    Reply
  85. чрезвычайные происшествия September 16th, 2009

    Последний из этих афоризмов уже цитировался в одной из дискуссий. Но мне очень хочется привести его и здесь. А ещё войти в круг уважаемых авторов:

    Reply
  86. monstroryuike September 22nd, 2009

    111111111111111111111111111111111

    Reply
  87. пища для детей September 28th, 2009

    Хорошая мысль. И вообще все в нашей жизни можно связать с детьми. Так что советую глянуть одним глазком – выдержка детей

    Reply
  88. Operew October 4th, 2009

    in principle the idea is interesting
    Плинтус
    костыль
    бинт

    Reply
  89. flood cellphone November 3rd, 2009

    Big thanks…)

    Reply
  90. http://indigohealth.ru November 4th, 2009

    Thanks!) good site..

    Reply

Leave a reply