1

I have a shortcode to create columns, such that the page in the editor (text view) looks like this;

[two-column]<ul>
    <li>Annual statutory accounts preparation</li>
    <li>Independent Examination service</li>
    <li>Audit file preparation</li>
    <li>Gift Aid returns</li>
    <li>Payroll</li>
</ul>[/two-column]
[two-column]<ul>
    <li>Bookkeeping service</li>
    <li>Management accounts</li>
    <li>Charity Commission administration service</li>
    <li>OSCR administration service</li>
    <li>Companies House administration service</li>
</ul>[/two-column]

Unfortunately when on the page it appears like this;

<p><div class="two-column">
<ul>
<li>Annual statutory accounts preparation</li>
<li>Independent Examination service</li>
<li>Audit file preparation</li>
<li>Gift Aid returns</li>
<li>Payroll</li>
</ul>
<p></div><br />
<div class="two-column">
<ul>
<li>Bookkeeping service</li>
<li>Management accounts</li>
<li>Charity Commission administration service</li>
<li>OSCR administration service</li>
<li>Companies House administration service</li>
</ul>
<p></div></p>
</div>

Now I don't want to remove all <p> tags (by manipulating wpautop), so how do i process this shortcode.

The shortcode;

function column_shortcode($atts = [], $content = null)
{
   $content = '<div class="two-column">'.$content.'</div>';

   return $content;
}

add_shortcode('two-column', 'column_shortcode');
  • So you want to get rid off all the paragraph tags? please paste your shortcode function as well. – Ahmed Fouad Sep 25 '16 at 14:53
  • Putting the first shortcode's closing [/two-column] and second's opening [two-column] on the same line and using the solution for this question should do the trick: wordpress.stackexchange.com/questions/239620/… – Dave Romsey Sep 25 '16 at 19:54
  • @DaveRomsey yes, that seems the simple solution but it's a question of getting the enduser to remember this. Yes, they will notice the extra space and bells will ring but it's not elegant and elegance is what we crave ;-) – Chris Pink Sep 27 '16 at 8:15
  • it seems like what is needed is the reverse of wpautop() – Chris Pink Sep 27 '16 at 8:18
1

OK, it seems someone has trod this path and there is in fact.... shortcode_unautop()

Job Done. It looks elegant in the editor and works in the output.

The shortcode now looks like this;

function column_shortcode($atts = [], $content = null)
{
   $content = '<div class="two-column">'.$content.'</div>';

   $content = shortcode_unautop($content);

   return $content;
}

add_shortcode('two-column', 'column_shortcode');

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.