WordPress.org

Forums

Using content_edit_pre not working (2 posts)

  1. katmac_aus
    Member
    Posted 1 year ago #

    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?

  2. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic