• Hello.

    I use FCKeditor to add text in posts. Now I want to use phpcode in posts and there is a plugin(PHPEXEC) that can do that but when I use this in FCKeditor nothing happens only that the php code is changed into something that is not [php code anymore. is this beacause I use fckeditor? or is there an other way to use php code in a post?

    Greetz Renzo

Viewing 1 replies (of 1 total)
  • Do you want to run the PHP, or just display it? If you just want to display it, put the code below in your functions.php file to add the [ raw] … [ /raw] shortcode (without the spaces) for displaying code in your posts:

    <?php
    function raw_formatter($content) {
      // Shortcode [ raw] ... [ /raw] to preserve code formatting
       $new_content = '';
       $pattern_full = '{(\[raw\].*?\[/raw\])}is';
       $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
       $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
    
       foreach ($pieces as $piece) {
          if (preg_match($pattern_contents, $piece, $matches)) {
            $new_content .= htmlspecialchars($matches[1]);
          } else {
             $new_content .= wptexturize(wpautop($piece));
          }
       }
    
       return $new_content;
    }
    remove_filter('the_content', 'wpautop');
    remove_filter('the_content', 'wptexturize');
    
    add_filter('the_content', 'raw_formatter', 99);
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘phpexec in post’ is closed to new replies.