Even though I have disabled autop for shortcodes, I end up with a lot of extra <p> tags in the generated form. Here's a snippet:

<div id="editrow-email-Primary" class="crm-section editrow_email-Primary-section form-item">
  <div class="label">
    <label for="email-Primary"> Email
      <span lass="crm-marker" title="This field is required.">*</span>
  <div class="edit-value content">
    <input maxlength="254" size="30" name="email-Primary" type="text" id="email-Primary" class="big crm-form-text required" />
<div class="clear"></div>

Note the stray </p><p> in the middle. But while a bit wrong, this is ok. What's really a problem is that the generated JS code for the datepicker also gets a bunch of random <p> tags:

<script type="text/javascript">/*<![CDATA[*/</p><p>CRM.$(function($){</p><p>var $dateElement=$('input[name=birth_date_display_57599e0ccbe99].dateplugin:not(.hasDatepicker)');</p><p>

This completely breaks the JS.

Any hints on how to figure out where these tags are coming from would be helpful. This sure looks like autop acting up, but I don't see how it could affect the shortcode's generated content, even when it might wrap the shortcode itself.

  • What CiviCRM version? Also have you tried switching to the default Wordpress theme? – Andrei Jun 9 '16 at 18:01
  • @Andrei - thanks for the response. I'm sure it was specific to my theme (see my answer below). – Dave Rolsky Jun 9 '16 at 21:55
  • @autarch glad you figured it out. Voted up. What theme are you using, just to be aware in the future. – Andrei Jun 9 '16 at 22:09
  • @Andre - it's a customized theme based off The Bootstrap theme. – Dave Rolsky Jun 10 '16 at 3:20

Ok, I figured it out. Here's the auto-relevant bits from functions.php:

function better_wpautop($pee){
    return wpautop( $pee, $br=0 );

/* This is a hack to make sure that wordpress's autop filter doesn't apply to shortcodes */
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'better_wpautop', 11 );
add_filter( 'the_content', 'shortcode_unautop', 12 );

I thought shortcode_unautop was supposed to fix this, but I took a look at it and it's a huge hack that tries to strip p tags back out of shortcode content in a truly terrifying way with a regex (ob Zalgo reference). So I made a copy of my standard page template and added the following to the top:

remove_filter( 'the_content', 'better_wpautop', 11 );
remove_filter( 'the_content', 'shortcode_unautop', 12 );

Now there is nothing autop related happening, which is fine, since the entire content of the page comes from the CiviCRM profile.

| improve this answer | |
  • Just want to check- was the issue in your local site? I just checked a few of ours and I am not getting any random <p> tags – Kevin Cristiano Jun 9 '16 at 19:21
  • @KevinCristiano - I wouldn't be surprised if it was specific to how autop was configured on my site. That said, the config I used (with the altered filter stack) is recommended in various places where people have discussed issues with the WP autop feature, so I wouldn't be surprised if someone else encountered it. – Dave Rolsky Jun 9 '16 at 21:53
  • @KevinCristiano - argh, hit enter too soon. I think it'd be nice if CiviCRM could disable autop for the content that it generates somehow. I don't know if that's possible. – Dave Rolsky Jun 9 '16 at 21:54

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.