Title: Php in posts&#8230;
Last modified: August 18, 2016

---

# Php in posts…

 *  [xerocool](https://wordpress.org/support/users/xerocool/)
 * (@xerocool)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/)
 * How can i have php in posts?……

Viewing 15 replies - 1 through 15 (of 15 total)

 *  [Minna](https://wordpress.org/support/users/minna/)
 * (@minna)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105589)
 * That requires a plugin. See for example [this](http://blog.idahocline.com/index.php/archives/2004/05/27/php-tag-within-a-post/)
   or [this](http://mark.scottishclimbs.com/archives/2004/07/02/running-php-in-wordpress-posts/).
   I use the latter one.
 *  Thread Starter [xerocool](https://wordpress.org/support/users/xerocool/)
 * (@xerocool)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105592)
 * Yeh…Heres the problem:
    For Marks Hack ([http://mark.scottishclimbs.com/archives/2004/07/02/running-php-in-wordpress-posts/](http://mark.scottishclimbs.com/archives/2004/07/02/running-php-in-wordpress-posts/)),
   I get this error: Warning: Cannot modify header information – headers already
   sent by (output started at /home/xero1/public_html/wp-content/plugins/runphp.
   php:46) in /home/xero1/public_html/wp-admin/post.php on line 342 In the comments,
   It said not to have no space after ending ?>. I made sure i didn’t and i still
   get the error. For this plugin ([http://blog.idahocline.com/index.php/archives/2004/05/27/php-tag-within-a-post/](http://blog.idahocline.com/index.php/archives/2004/05/27/php-tag-within-a-post/)),
   I get: Parse error: parse error, unexpected $ in /home/xero1/public_html/my-hacks.
   php on line 8 Please help :(!@
 *  Thread Starter [xerocool](https://wordpress.org/support/users/xerocool/)
 * (@xerocool)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105594)
 * Gonna try now ;).
 *  Thread Starter [xerocool](https://wordpress.org/support/users/xerocool/)
 * (@xerocool)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105595)
 * Ok. So i added this code:
    <?php function run_phpinpost($data) { $PHPTag = “phpcode”;
   $data = str_replace(array(“rn”,”r”), “n”, $data); while (false !== strpos($data,“
   < “.$PHPTag .”>”)) { $Before= substr($data, 0, strpos($data, “< “.$PHPTag.”>”));
   $After = substr($data, strpos($data, “</>”)+(strlen($PHPTag)+3)); $Evaluate =
   substr($data, strpos($data, “< “.$PHPTag.”>”)+(strlen($PHPTag)+2)); $Evaluate
   = substr($Evaluate,0,strpos($Evaluate, “</>”)-1); $Evaluate = str_replace(array(“’”,”‘”),”‘”,
   $Evaluate); $Evaluate = str_replace(array(“””,”“”),'”‘, $Evaluate); ob_start();//
   run that data and grab what comes out eval($Evaluate); $data = $Before.ob_get_clean().
   $After; } // end of while return $data; } // end of run_phpinpost add_filter(‘
   the_content’, ‘run_phpinpost’); // To add compatibility with earlier PHP version…(
   before 4.3.0) if (!function_exists(“ob_get_clean”)) { function ob_get_clean(){
   $ob_contents = ob_get_contents(); ob_end_clean(); return $ob_contents; } } ?>
   And get this now: Parse error: parse error, unexpected $ in /home/xero1/public_html/
   my-hacks.php on line 12
 *  Thread Starter [xerocool](https://wordpress.org/support/users/xerocool/)
 * (@xerocool)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105599)
 * Can you do it please? I suck @ doing it 🙁
 *  Thread Starter [xerocool](https://wordpress.org/support/users/xerocool/)
 * (@xerocool)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105601)
 * I tried inserting this:
    <phpcode>< ?php include (“wp-user.php”) ; ?></phpcode
   > So it comes out in the post as: < ?php include (“wp-usen.php”) ; ?> When i 
   end it, It comes out as: <phpcode>< ?php include (“wp-user.php”) ; ?></></phpcode
   > WTF?
 *  Thread Starter [xerocool](https://wordpress.org/support/users/xerocool/)
 * (@xerocool)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105603)
 * Yep.
    I inserted: < phpcode ><?php include (“wp-user.php”); ?></ phpcode >
 *  [Minna](https://wordpress.org/support/users/minna/)
 * (@minna)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105604)
 * I edited my previous post and added that example code of < phpcode >include()
   </ phpcode > , meaning that you probably don’t put the “< ? php” and “?>” part
   in the code but only the actual code. At least that’s how the hack I use works
 *  Thread Starter [xerocool](https://wordpress.org/support/users/xerocool/)
 * (@xerocool)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105605)
 * Tried this:
    < phpcode >include(“wp-user.php”; )</ phpcode > And it comes out
   in bold: include(“wp-usen.php”; )
 *  [Minna](https://wordpress.org/support/users/minna/)
 * (@minna)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105606)
 * it’s supposed to be include(“wp-user.php”);
 *  Thread Starter [xerocool](https://wordpress.org/support/users/xerocool/)
 * (@xerocool)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105607)
 * Then it comes out as in bold:
    include(“wp-usen.php”);
 *  [Minna](https://wordpress.org/support/users/minna/)
 * (@minna)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105609)
 * I’m stumped… Maybe some one more clever than me can help you out. Or maybe you
   could ask at IDaho Cline’s blog…
 *  Thread Starter [xerocool](https://wordpress.org/support/users/xerocool/)
 * (@xerocool)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105617)
 * *Bump*
    ok
 *  [Mark (podz)](https://wordpress.org/support/users/podz/)
 * (@podz)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105618)
 * I think you should clearly clarify precisely what it is you want.
    As we discussed
   on #irc, you don’t want the actual code to be shown. You want a script that when
   you enter something, it prints to the screen ? Yes ? How must this be different
   from what WP actually does ? (And please don’t bump this soon: [http://www.tamba2.org.uk/wordpress/forum/](http://www.tamba2.org.uk/wordpress/forum/))
 *  [Minna](https://wordpress.org/support/users/minna/)
 * (@minna)
 * [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105706)
 * I understand the need to be able to use php in a post (for example including 
   a file etc.), but as I said, for me one of the plugins worked perfectly. And 
   if you bumped me, I was half asleep and half watching Psycho III, it was, after
   all, way past midnight. (And I’m not a “committed” forum replier anyway.)
    What
   I was going to come ask after Psycho, XeroCool, was that you did enable myhacks
   in the options, didn’t you? Which version of WP you use? If it’s 1.2., maybe 
   you should look into the Mark’s hack because I have 1.2. (and it works for me,
   as stated) and the headers already sent error is probably easier to solve. There
   is another current thread on this which *just* disappeared off the latest discussions
   list but it’s there… there was another plugin/hack link so check that out too*
   blabber* sorry

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Php in posts…’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 15 replies
 * 3 participants
 * Last reply from: [Minna](https://wordpress.org/support/users/minna/)
 * Last activity: [21 years, 7 months ago](https://wordpress.org/support/topic/php-in-posts/#post-105706)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
