Title: stop wordpress from striping php code in post content
Last modified: August 19, 2016

---

# stop wordpress from striping php code in post content

 *  [arpitap](https://wordpress.org/support/users/arpitap/)
 * (@arpitap)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/stop-wordpress-from-striping-php-code-in-post-content/)
 * I am using exec-php plugin and want to write php code in posts and pages without
   disabling visual editor.
 * is there any plugin to do that? or any other way to do this?
 * I really need this, if anyone can help me then it would be great.
 * Thanks in advance.
 * Arpita

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

 *  [Jacotheron](https://wordpress.org/support/users/jacotheron/)
 * (@jacotheron)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/stop-wordpress-from-striping-php-code-in-post-content/#post-1768075)
 * I do not think that it is possible. If you want some php code to execute, you
   need to define it as shortcode in a plugin.
 * WP will strip all php code as it can’t check it and be sure that it is not malicious
   code.
 * I suggest writing a plugin that registers the useful shortcodes that you need
   and using them.
    I hope that this helps. Jacotheron
 *  [Ad Lagendijk](https://wordpress.org/support/users/adlag/)
 * (@adlag)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/stop-wordpress-from-striping-php-code-in-post-content/#post-1768336)
 * I have done just that. See [Example in Dutch](http://www.stringcat.com/adblog/2010/10/18/nieuwe-chaos-bij-rabo-reken-hier-zelf-de-kosten-uit-van-een-lopende-rekening/).
   Although this is in Dutch you can see the effect. The calculator at the end is
   an included php file containing an Ajax form. I do not agree with the developer
   of the plugin that TinyMCE does not go together with php code. I use php by using
   an include php file as I want to separate code from html, to keep the post manageable.
   I can edit the post in TinyMCE. The post will show the include directive
    <?php
   include_once(‘xxxxx.php’) ; ?> in wysiwg-view and &lt ;?php include_once(‘xxxxx.
   php’) ;  &gt ;?php in html-view (without the spaces for the semi-colons).
 * All the action is in the runtime.php file.
 * I will tell you my solution:
 * (i)
    I do not want to the plugin to be activated for every post as php execution
   is a danger anyway. So I define a meta-tag ‘php-exec’ and only if it ==1 the 
   plugin will do its job. So right at the beginning of the function “eval_php()”
   I introduce:
 *     ```
       //
       // BEGIN CHANGE BY YOUR NAME HERE
       //
         $post;
         if (isset($post)) {
           $custom_fields = get_post_custom();
           if (!isset ($custom_fields['php-exec'][0])){
             return $content;
           }
           if ($custom_fields['php-exec'][0] != '1') {
             return $content;
           }
         }
         else {
           return $content; // non-posts are returned without eval
         }
       //
       // END CHANGE BY YOUR NAME HERE
       //
       ```
   
 * (ii)
    In the same function, right before ob_start() I inserted:
 *     ```
       //
       // BEGIN CHANGE BY YOUR NAME HERE
       //
         $content = str_replace('&lt ;?php', '<?php', $content);
         $content = str_replace('?&gt ;', '?>', $content);
       //
       // remove spaces before semi-colons
       // END CHANGE BY YOUR NAME HERE
       //
       ```
   
 * (iii)
    The comments are necessary when later you want with a grep-like program
   to find all your changes. To prevent loosing your solution (and your edited file)
   on upgrading the plugin, rename the edited plugin slightly in the file php-exec.
   php and change author name etc. Reinstall the original plugin but do not activate
   it. When WordPress warns you that you should upgrade the original plugin you 
   will see immediately below or above it in the plugin list your own version. Then
   you upgrade and edits the new file again with the still present old edited file.
 * (iv)
    The drawback with my solution is that if your original post contained already(
   although not very likely) ‘&lt ;?php’ this will be activated in a real ‘<?php’.
   Not what you want and possibly dangerous. The meta tag protects you already from
   this to a certain extent. A better way would be to use something more unique 
   like ‘&lt ;?php&lt ;?php’ as the string to be replaced.
 * (v)
    I have tried a number of other solutions, but in the above solution all 
   the global variables are visible from within the included file.

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

The topic ‘stop wordpress from striping php code in post content’ is closed to new
replies.

 * 2 replies
 * 3 participants
 * Last reply from: [Ad Lagendijk](https://wordpress.org/support/users/adlag/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/stop-wordpress-from-striping-php-code-in-post-content/#post-1768336)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
