Shortcodes Broken again in latest update

The issue I reported previously was (partially) resolved in 2.1.0 (the use of columnize shortcode around other shortcodes still resulted in some empty

tags, but I dealt with that in functions.php and had not reported back as yet.)

However all shortcodes are broken again in 2.1.4 - my original thread is here…

I note that the 2.1.4 changelog lists:

BUGFIX: <p> and <br> tags appearing when using classic shortcodes.

…I assume this has something to do with why this is now broken again!

Hi there,

Could you please provide a link to the page where you’re experiencing issues?

Also, please let us know of any code you have active that is currently modifying the p tag behavior. Have you tried disabling it after updating to the latest version?

The problem occurs on any single item, I have already removed the additional code.

I think perhaps my initial reported problem was misunderstood which is why I say this was partially fixed in 2.1.0.

ALL shortcodes used at the beginning of a paragraph are not wrapped in a p - if you look below you will see the empty p that should wrap it!

The reason for my additional code is that I am using the columnize shortcode to create 2x columns in my articles and within the columns I am using additional shortcodes - 2.1.0 resolved the problem of the shortcodes not wrapping but using columnize around other shortcodes resulted in 2x empty p tags, one at the beginning of column 1 and another at the end of column 2. Hence my additional code.

I’ll post a secure note with a link to a blog post (does not use the columnize shortcode) and a link to my CPT which does use columnize. None of these are using Cornerstone btw.

Hi,

Would you mind providing us with login credentials so we can take a closer look? Please provide following information:

Set it as Secure Note

  • Link to your site
  • WordPress Admin username / password

Thanks

I have already gone through this in the previous thread.

FYI - I have updated to 2.1.5 and tested again with all plugins disabled and the parent theme activated. The problem is still present so you should be able to test this on your side without needing access to my site.

I do not have time to wait another 24hrs for your response I am very busy with other things - I have instead sent a private message to @christopher.amirian and would appreciate it if you escalate this issue to a senior dev.

Hi Borde,

This is a unique case as the columnize shortcode has not been commonly used since Cornerstone was released. I’ve checked your page, but I’m still unable to determine why this is happening.

First, could you try adding this code to functions.php of a child theme?

add_filter( 'the_content', 'cs_noemptyp' );

Let me know if that makes a difference. If not, please add login credentials (WordPress admin and FTP) and we can take a closer look. Thanks!

Hi,

I appreciate that my use of columnize may be unique, however this does not explain the broken shortcodes in the blog that does not use columnize…

Adding the code above does nothing as there are no empty p tags present - nor does it fix the broken shortcodes!

Like I said - the main issue is any shortcode used at the beginning of a paragraph causes the p to break and an empty one appears below - this happens on the dropcap and the highlight, I have not tested any others as yet.

I only had to remove the 2x empty p’s when I applied the 2.1.0 update (which contained what was supposed to be a fix for this issue) and that only applied to the articles where columnize is being used. It was fine on 2.1.1 - 2.1.2 2.1.3 and broke again in 2.1.4

The blog post I link to above DOES NOT use columize but you will see that the dropcap and highlight at the beginning of the paragraph breaks the p’s

With regards to cs_noemptyp I suggest you read the original thread again as I have said that it is this function that is breaking the p’s

function cs_noemptyp( $content ) {

$array = array(
	'<p>['    => '[',
	']</p>'   => ']',
	']<br />' => ']',
);

$content = strtr( $content, $array );

return $content

Hi @Borde,

Please provide your FTP credentials as requested.

I also copied your content to my installation and it works as expected, the first paragraph is wrapped by <p></p> without a need to remove that code.

Thanks!

Well, lucky you - god knows why I’m having an issue here then, I have tested with the parent theme active and all plugins off several times so this was unexpected. I have just tested again and the problem persists.

Hey Dominik,

Sorry for the confusion. @Rad must have been using Pro 2.1.3 where the fix for Classic Shortcodes Breaking was not yet introduced.

Now for the issue, we would need to target [dropcap] and [highlight] or any other shortcodes at the start of the paragraph or start of the line specifically to retain the bug fix and wpautop. A code like the one below should fix this temporarily. It only targets the dropcap and hightlight shortcodes. I tested this in my child theme’s functions.php and it works.

add_filter( 'the_content', 'add_p_at_shortcode_begin' );

function add_p_at_shortcode_begin( $content ) {
	
	$patterns = array();
	$patterns[0] = '/(?s)\[dr/'; $replacements[0] = '<p>[dr';
	$patterns[1] = '/(?s)\[hi/'; $replacements[1] = '<p>[hi';
	
	return preg_replace($patterns, $replacements, $content);
}

In case a reader wonders where the end </p> tag is, wpautop will take care of that so it is important to note that it should not be disabled for this case.

Here’s my content:

Here’s the output without the fix:

Here’s the output with the fix:

I’ll post this in our issue tracker. Please stay tuned for updates and if there’s an official fix for this, please remove the given code.

Hope that helps.

Christian,

The filter provided as a workaround is not really required (and looks suspiciously like my adjustment to cs_noemptyp in the original thread - I didn’t go this route as I assumed the code would need to target all shortcodes and may need to include any 3rd party ones if used at the beginning of the paragraph) - I would just like the issue resolved officially. I am not using Cornerstone for these sections but do want to build out my pages with it so I don’t want to poke things my side and end up breaking Cornerstone.

If (as I believe) this behaviour is the result of cs_noemptyp - I did find a ‘solution’

If you comment out the following part of that function in helpers.php:

$content = strtr( $content, $array );

and instead use:

$content = shortcode_unautop( $content);

The Shortcodes are no longer broken! - I discovered this by first changing it to:

$content = $content;

Which returns the content with empty p tags around the shortcodes!!!

The only remaining issue is the additional p at the beginning of the first column and the end of the second on the articles using columnize (blog posts seem fine and no sign of any empty p’s here). I used the following in functions.php to remove them…

add_filter('the_content', 'remove_empty_p', 20, 1);
function remove_empty_p( $content ){
    $content = force_balance_tags( $content );
    $content = preg_replace( '#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content );
    $content = preg_replace( '~\s?<p>(\s|&nbsp;)+</p>\s?~', '', $content );
    return $content;
}

But as I’m not entirely sure why this function exists (i.e. your reasoning for doing it this way) I don’t know if this is the answer… or what effect it has on Cornerstone etc.

Anyway, I look forward to an official PERMANENT fix - I have not as yet migrated the content from the old site so will put that on hold for the time being.

Thanks for acknowledging/confirming that this issue does exist and I’m not going mad!

Hey Dominik,

I realized the first code I provided had a problem where it added <p> tag in before all highlights. I have updated it now to target only highlights in the beginning of the paragraph or line. Please see my previous response.

The issue is caused by cs_noemptyp and wpautop. Those empty <p></p> tags are outputted by wpautop that is why if you modify cs_noemptyp, it will bring back the <p> before the start of ALL the shortcodes solving the issue but introducing another issue with other classic shortcodes. The updated code (please check my updated previous response) I provided will target ALL DROPCAPS AND HIGHLIGHT SHORTCODES that is added at the start of the paragraph. Why we need to target them specifically is because we also need the cs_noemptyp in order for other shortcodes not to break. If you don’t need other shortcodes, then it would be ok to modify cs_noemptyp thus reverting to the behavior before Pro 2.1.4.

Thanks.

Trust me, I totally understand the issue!

What I mean is why do you do:

$content = strtr( $content, $array );

and not:

$content = shortcode_unautop( $content);

???

I have just tested this and a page created with cornerstone LOOKS ok - but I have not tried the editor or looked at the output… it does SEEM to work though!

LOL - I shouldn’t have asked - I’m now looking at the output from a Cornerstone page - is it correct that the the text block is not wrapped in a p tag???

Doing $content = shortcode_unautop( $content); will revert to the old behavior prior to Pro 2.1.4. It will fix your issue but will introduce issues with other shortcodes such as if you prettify the Block Grid shortcode like this.

[block_grid type="two-up"]
[block_grid_item]
[image src="http://yoursite.com/image.jpg" alt="Place Alt Text Here" type="thumbnail"]
[/block_grid_item]
[block_grid_item]
[image src="http://yoursite.com/image.jpg" alt="Place Alt Text Here" type="thumbnail"]
[/block_grid_item]
[block_grid_item]
[image src="http://yoursite.com/image.jpg" alt="Place Alt Text Here" type="thumbnail"]
[/block_grid_item]
[block_grid_item]
[image src="http://yoursite.com/image.jpg" alt="Place Alt Text Here" type="thumbnail"]
[/block_grid_item]
[/block_grid]

When strictly, it should be written like this:

[block_grid type="two-up"] [block_grid_item] [image src="http://yoursite.com/image.jpg" alt="Place Alt Text Here" type="thumbnail"] [/block_grid_item] [block_grid_item] [image src="http://yoursite.com/image.jpg" alt="Place Alt Text Here" type="thumbnail"] [/block_grid_item] [block_grid_item] [image src="http://yoursite.com/image.jpg" alt="Place Alt Text Here" type="thumbnail"] [/block_grid_item] [block_grid_item] [image src="http://yoursite.com/image.jpg" alt="Place Alt Text Here" type="thumbnail"] [/block_grid_item] [/block_grid]

The pretty form will break without cs_noemptyp.

Thanks.

Understood - thanks!

Regarding the text not wrapped in Cornerstone. wpautop will not work when if you’re using the HTML editor. Switch to Rich Text and it will be wrapped.

ahhh, ok - that was done using one of the templates. I haven’t actually used Cornerstone very much as yet - that comes when it’s time to do the pages!

thanks again, have a good weekend.

You are most welcome. Have a great weekend my friend. :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.