Site logo

Archived topic

Can I filter out   in content?

3 replies · Started by Ben on August 31, 2022

Viewing posts 1–4 of 4

I have content that has   in various places. In certain areas this is causing a problem (it's complicated but is due to Arabic font issues).

Is there a way I can stripe this (   ) out of single content (single post page)?

Thanks

Hi there,

WordPress has the the_content filter hook:

https://developer.wordpress.org/reference/hooks/the_content/

You can try string replacing the &nbsp whilst in a single post with this PHP Snippet:

add_filter( 'the_content', function( $content ) {
    if ( is_single() ) {
        $content = str_replace( "&nbsp","", $content );
    }
    return $content;
}, 999, 1 );

nice one, many thanks, tweaked it a bit to swap for a normal space and include the semi-colon

add_filter( 'the_content', function( $content ) {
    if ( is_single() ) {
        $content = str_replace( " "," ", $content );
    }
    return $content;
}, 999, 1 );

Glad to be of help

This archived topic is closed to new replies.