WordPress.org

Support

Support » How-To and Troubleshooting » Using content_edit_pre not working

Using content_edit_pre not working

  • I want to wrap span tags with a hightlight class around shortcodes when viewing content in the editor. This way I can apply a css style to and a background colour to shortcodes to its easier for my client to know not to edit them.

    The way I am trying to do is is by using the content filters to modify the content before it goes to the editor and then again before its saved. I would write a simple str_replace function to insert/remove my span tag.

    My problem is that the add_filter(‘content_edit_pre’) is working. Here is my code:

    add_filter( 'content_edit_pre', 'sq_add_highlights', 1, 2 );
    function sq_add_highlights( $content, $post_id ) {
    
            $content = str_replace('[','<span class="highlight">[',$content);
    	$content = str_replace(']','</span>',$content);
    
        // Returns the content.
        return $content;
    }

    This is doing nothing with the content. It is appearing just the same. I also tried using $content = "test" as a way to see if the filter was applying. When I did that it outputted the content as “test”.

    So why is string replace not working?

Viewing 1 replies (of 1 total)
  • Pioneer Web Design
    Participant

    @swansonphotos

    I want to wrap span tags with a hightlight class around shortcodes when viewing content in the editor. This way I can apply a css style to and a background colour to shortcodes to its easier for my client to know not to edit them.

    This is a website dev. issue, not a WP troubleshooting issue.

Viewing 1 replies (of 1 total)
  • The topic ‘Using content_edit_pre not working’ is closed to new replies.