• Hi,
    I want to write a plugin to display programming code and do some syntax highlighting. However, when I try the very simple code below (which extracts code blocks and adds a string for testing purposes), the contents of my posts is not displayed anymore. What am I doing wrong?

    <?php
    /*
    Plugin Name: Code Plugin
    */

    function processcode($matches)
    {
    $temp = $matches[2].’ tarara’;
    return $temp;
    }

    function extractcode($text)
    {
    $newtext = preg_replace_callback(‘/()(.*)()/’,’processcode’,$text);
    return $newtext;
    }

    add_filter(‘the_content’, ‘extractcode’);

    ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Tested your plugin and it’s working fine on a couple setups of mine. Possible you have a conflict with A. another plugin, or B. some customization to your templates.

    Thread Starter pieterprovoost

    (@pieterprovoost)

    I don’t have any other plugins activated, but I did some customization to the template. You can see it at http://www.pieterprovoost.nl/wordpress/. I didn’t change much in the “post” code, except for some translations.

    The code looks like this:


    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanente link naar <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <small><?php the_time('j F Y') ?> <!-- by <?php the_author() ?> --></small>
    <div class="entry">
    <?php the_content('Lees het vervolg van dit item &raquo;'); ?>
    </div>
    <p class="postmetadata">Gepost in <?php the_category(', ') ?> | <?php edit_post_link('Bewerk', '', ' | '); ?> <?php comments_popup_link('Geen reacties ', 'Eén reactie ', '% reacties '); ?></p>
    </div>

    Thread Starter pieterprovoost

    (@pieterprovoost)

    I tried changing the “post” code back to the original, but that didn’t help. Any thoughts would be more than welcome!

    Thread Starter pieterprovoost

    (@pieterprovoost)

    This problem is still unresolved. I tried using Semicolon’s code plugin and this works fine, although it basically does the same thing (preg_replace_callback of code tags)…

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘plugin using preg_replace_callback’ is closed to new replies.