1

I am using the SimpleReach plugin that adds some content to every post using the content hook. The content that is being added is

<!-- SimpleReach Slide Plugin Version: {{srslide_plugin_version}} -->
<script type='text/javascript' id='simplereach-slide-tag'>
    __reach_config = {
      pid: '{{srslide_pid}}',
      title: '{{title}}',
      tags: {{{tags}}},
      authors: {{{authors}}},
      channels: {{{channels}}},{{slide_logo_elem}}
      slide_active: {{srslide_disable_on_post}},{{slide_icon_elem}}
      date: '{{published_date}}',
      url: '{{canonical_url}}',
      header: '{{srslide_header_text}}'
    };
    var content = document.getElementById('simplereach-slide-tag').parentNode, loc;
    if (content.className){ loc = '.' + content.className; }
    if (content.id){ loc = '#' + content.id; }
    __reach_config.loc = loc || content;
    (function(){
    var s = document.createElement('script');
      s.async = true;
      s.type = 'text/javascript';
      s.src = document.location.protocol + '//d8rk54i4mohrb.cloudfront.net/js/slide.js';
      __reach_config.css = '{{srslide_css_url}}';
      var tg = document.getElementsByTagName('head')[0];
      if (!tg) {tg = document.getElementsByTagName('body')[0];}
      if (tg) {tg.appendChild(s);}
    })();
</script>

However Wordpress is sanitizing the content by adding extra breaks and paragraphs before and after.

I want to disable autop only for this content so that breaks/paragraphs aren't added.

Is there a way to do it?

1

A couple of caveats before beginning. It tried to run that plugin but apparently I have to register with a third party site before I can use it, so that throws a wrench in testing.

Second, I am having trouble duplicating this problem. That may be because I have beaten my dev stack up too much and it is time to wipe it clean and start over (which it is), so that said...

wpautop runs on the entire post content. You can't, by any means that I am aware, restrict it to run on only part of the content.

I have not installed and tested that plugin so I can't confirm that your analysis of the problem is correct, but in general there are several things that you can do to avoid having wpautop mangle content:

  1. Register and enqueue the script so as to avoid shoving this into the post body at all.
  2. Remove all the line breaks and extra whitespace from that block of code. None of that is necessary and without it wpautop would have nothing to bite into.
  3. Insert the content very late via a priority when the callback is added to the_content

The only one that you may be able to effect is #3. The script adds that code by means of: add_filter('the_content', 'srslide_insert_slide_js');. You should be able to remove that with remove_filter('the_content', 'srslide_insert_slide_js'); and add it back with add_filter('the_content', 'srslide_insert_slide_js',1000); to get it to run after wpautop.

|improve this answer|||||
  • Thanks for the help, I am reading your answer now but I did it the same way you described. Sorry about the testing part, this plugin was already installed on client's website and I was directly working on the live site (I know its bad). I just modified the plugins code to add_filter('the_content', 'srslide_insert_slide_js', 999); – Atif Mohammed Ameenuddin Jul 28 '13 at 18:34
  • You marked this as accepted. I assume what you did to fix the problem was suggestion #3? – s_ha_dum Jul 28 '13 at 18:35
0

I don't think you can setup autop like this.

The only idea that comes to my mind is to set a post meta after you insert the post and then setup a condition in functions.php.

I don't know how the post is added by that plugin, but you will need to retrieve its ID.

Then use this to add the meta:

<?php add_post_meta($post_id, 'no_autop', 'true'); ?> 

Then disable autop on posts with that meta by adding this to functions.php:

if(get_post_meta( $post_id, 'no_autop', true )=='') {
remove_filter( 'the_content', 'wpautop' );
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.