Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #777243

    For some reason there appear random non-breaking spaces on our site: openstack.hosting, what’s even weirder is that these are not being rendered properly causing the words separated by the nbsp to stick together.

    After quite some searching I found that this is probably a TinyMCE issue for which I found the following solution: https://ckmacleod.com/2017/03/23/exterminating-non-breaking-space-bug/

    So I created a Child Theme for Enfold using http://kriesi.at/documentation/enfold/using-a-child-theme/, I’ve imported all the settings and all is good in the world. Except for those pesky nbsp’s that are still appearing randomly in my content ;)

    However, when I edit my Child Theme’s function.php and add the following code it literally does nothing when I save content using the Avia editor:

    /* remove all nbsp's when content is saved */
    add_filter('content_save_pre','remove_buggy_nbsps',99, 1);
    
    function remove_buggy_nbsps($content) {
       //strip both types of non-breaking space in case NGG or similar is installed
       $content = str_replace(' ',' ',$content); 
       $content = str_replace('\xc2\xa0',' ',$content); 
    
       return $content;
    }

    I’ve added some debug code to this custom function and by the looks of it, it is simply never called. So I suspect I need to find another hook to filter the content as soon as it is saved from the Avia editor.

    Does anyone have an idea how to add a filter to my child theme’s functions that will sanitize page content once I update or add it?

    • This topic was modified 7 years ago by ServerBiz.
    #777905

    Hey ServerBiz,

    Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look.

    Best regards,
    Victoria

    #779180

    Hi Victoria,

    I have removed all the nbsp’s by hand, so there isn’t much to see. I would just like to know which hook I can use to filter the content before it gets saved to the database.

    Kind regards,

    Roy

    #779191

    Hi Roy,

    I think you already used the hook content_save_pre which is used to sanitize content prior to saving in the database which should trigger when you update a page/post. If you want to easily remove this try using Search and Replace plugins.

    Best regards,
    Nikko

    #779210

    Hi Nikko,

    in that case can you verify this trigger is working? I created a child-theme, but I don’t think the trigger is successfully being called.

    Thanks,

    Roy

    #779873

    Hi ServerBiz,

    You can add a line of code that would write to the log if the function gets called you can debug it.

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #788517

    I have tried logging, even a “die();” command does nothing, basically I would like to know if I’m using the right hook. Should “content_save_pre” work?

    #788621

    Hi ServerBiz,

    Best regards,
    Victoria

    #790203

    Hi Victoria

    • This reply was modified 6 years, 11 months ago by ServerBiz.
    #790521

    Hi ServerBiz,

    I think you should add some logging to that function, that way you will know whether it get’s called, I would also try logging the content it gets and what it returns. And just test with a simple element on a simple page built with Advanced Layout Builder.

    Best regards,
    Victoria

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.