-
AuthorPosts
-
April 13, 2017 at 1:18 pm #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, 7 months ago by ServerBiz.
April 14, 2017 at 5:37 pm #777905Hey 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,
VictoriaApril 18, 2017 at 11:03 am #779180Hi 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
April 18, 2017 at 11:15 am #779191Hi 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,
NikkoApril 18, 2017 at 11:47 am #779210Hi 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
April 19, 2017 at 10:25 am #779873Hi 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,
VictoriaMay 5, 2017 at 5:03 pm #788517I 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?
May 5, 2017 at 7:02 pm #788621Hi ServerBiz,
Best regards,
VictoriaMay 9, 2017 at 12:33 pm #790203Hi Victoria
- This reply was modified 7 years, 6 months ago by ServerBiz.
May 9, 2017 at 7:16 pm #790521Hi 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 -
AuthorPosts
- You must be logged in to reply to this topic.