Execute PHP in WordPress post, page and Widget Sidebar

Advertisement

phpwidget Execute PHP in Wordpress post, page and Widget Sidebar

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 the plugin.
  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. phpwidget Execute PHP in Wordpress post, page and Widget Sidebar

Share!

Enjoy the article so far? Recommend it to your friends and peers.

Subscribe! (free)

Be the first to our articles and get latest updates on freebies.

Advertisement

  • nice catring blog! i will be back here soon
  • it can't work well with my blog. I'm using WP 2.9. Are there any update that I can use?
  • Is it possible to execute PHP on my wordpress blog located on wordpress hosting stroyblog.wordpress.com?
  • Abbie
    Thanks so much!! Exactly what I needed. Works perfectly!
  • This did not work for me Im using 2.9. When I saved my work every thing was deleted.
  • Hey I've got a question:
    I'm trying to execute a php code in a page in wordpress and it works but I want the results to be shown above the page content.
    Right now I have the page content and after that I get the results from the php code.
    Any idea how to move the results from the php code above the page content ?
    here's my example http://csautocatania.ro/ and the php code is the text under the flaming soccer ball.
    Thanks in advance :)
  • Greate plugin! Now I can have full power in my blog engine. Thanks!
  • Finally, I use template to build the homepage of my site, but I need to edit the php file.
  • I can't complain, it seems to work with 2.9.1. Great plugin, thanks!
  • Hello, same as eric's problem above, hope someone could update the codes so it can run on WP 2.9.x.


    Thanks a lot!
  • Hope it will work in wp 2.9.x. I am currently using a page for the homepage (http://zhiqiangma.info). It will be better if this plugin works.
  • Lasse
    hope this works, its exactly what i was looking for!
    thanks a bunch, your a life saver.
  • i test with wp 2.9.1 not work too

    how?
  • It is working for me, I am using it ti insert randomly changing ads between the text in the posts
  • Happy Developer
    saved my life! many many thanks :)
  • Bowsie
    This doesn't work for me. I'm using 2.9 and neither phpexec1 nor phpexec2 had any effect even when I disabled my visual editor.

    Was ultimately a waste of time for me, hope the rest of you have more success.
  • Dude! It works! Muy bueno! Gracias!
  • Kenchappagoudra
    Thank you. It's nice tool.
  • vishal
    Hi,

    I have installed the plugin as suggested and also activated.
    But it is not working.

    Php Code:

    <?php
    echo 'vishal';
    ?>


    Please suggest.
  • Chris
    Dose this plug-in support the ability to display the custom fields of a post?

    I have placed the following code in a widget. It loops out the list but will not display the custom fields. I know the code is working because it is pulled from a working page template.











    ">




    error
  • Steve
    The code is out of date. This links to V 1.0 of the eidget code, it is currently at V 2.0
  • Great! Thanks a lot! That 's what I was looking for :)
  • This is exactly what I was looking for! Having the ability to run PHP inside pages saves me lots of time not having to create seperate pages outsude WP. Thanks!!
  • Новость реально порадовал. Автору респект и уважуха. В поддержку темы тоже делюсь тем, что близко мне - www.порно-онлайн.su, Заходите - не пожалеете
  • Thanks!) good site..
  • Big thanks...)
  • Operew
    in principle the idea is interesting
    Плинтус
    костыль
    бинт
  • Хорошая мысль. И вообще все в нашей жизни можно связать с детьми. Так что советую глянуть одним глазком - выдержка детей
  • Последний из этих афоризмов уже цитировался в одной из дискуссий. Но мне очень хочется привести его и здесь. А ещё войти в круг уважаемых авторов:
  • peter
    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
  • Wow it works for my new wordpress system i am building :) very nice thx
    Only i get errors wen i want to include :(
  • 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?
  • Jessica Rewnell
    I seriously don't understand how to get a wordpress sidebar!!!
  • 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...
  • hummm its not working for me
  • hmm..now this is some serious stuff. I hope that it will work with the latest version of WP
  • Mia
    I read your website every week, its great and got lots of information to take in and lots of interesting articles.
  • Cool servise - Trace ip tools
  • Thanks! works awesome !
  • oriclub
  • Чем мельче интересы мужчины, тем крупнее кажется ему каждая мелочь.
  • До сих пор ищите где продать? Тогда специально для вас наше предложение - интернет аукцион Украины
  • Недавно наткнулся на форум фанов, там действительно есть что почитать
  • Спасибо вам за сайт, очень полезный ресурс, мне очень нравится
  • MCA
    hi dude,
    this is awesome, thanks!
  • works for me, thanks
  • Arun Sukumar
    Hi Brother,
    Thanks for the plugin, Keep producing :)
  • Anne
    amazingly easy !
    Thanks.
  • yo
    thanks a lot man. huge help. been lookin for this for a while
  • Karl
    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.
  • Yahhh...same too me! Not work with Wp-2.7
  • 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
  • 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
  • Dave Hassen
    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.
  • Cool! I really helps!
  • 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 :)
  • Steve Rial
    It worked absolutely perfectly and was exactly what I needed. Thanks for the good work.
  • hi,
    its good site
  • I tried this and still got nothing but text on my page.
  • Excellent plugin. Thanks so much. Workin' just fine here on 2.6.2.
  • That plugin is save?
  • Mario
    Mmmmhhh the code in my prev comment got cut out...hope you get the whole deal on the admin side
  • Mario
    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-">










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


    Any idea?? Thanks
  • Steven
    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.
  • Judah Mu
    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
  • Unable to get working on v2.5, looking at RunPHP right now
  • Will it work on WP 2.5?
  • 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.
  • Dan Kelly
    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!!
  • Thanks so much for these codes, they are the way out for me!!! thanks!
  • Patu
    Hi, phpexec-2 dont work with wp 2.2.1 :(

    Help!!!
  • Ted
    Thanks, worked a treat.
  • 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 ;)
  • 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 ;)
  • stephen
    i haven't tested this yet, but for you 2.x.x+ users, try out this link here

    http://activeblogging.com/info/phpexec-2/
  • 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)
  • royalblogger
    Same here, not working with 2.1.1.
  • 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.
  • 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?
  • I'm using WP2.1.1 and it doesn't seem to work.
    Is there an alternative method to this?
  • 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.
  • I had been using this while i was on Wordpress 1.5.x, but does it work with Wordpress 2.1.1 now ??
  • 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 :)
  • 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.
  • Yeah, that's what i mean :) Me using the coding mode, the tag works fine.
  • 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
  • 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 :)
  • does it work with other wysiwyg editors like xinha4wp ?
  • its not working with any WYSIWYG
blog comments powered by Disqus