Shortcode not firing when using PRO

I have a shortcode [ld_course_list] that works when using the WP content edit page. But when I convert it to a Pro page and use a Classic Raw Element to add the shortcode doesn’t completely work.

I have traced the issue to this function from the shortcode:
https://pastebin.com/QNDZJUjs

From what I can tell is that nothing after line 9 is being returned. The CSS and the JS files are not loaded on the PRO page and the <div id='ld_course_list'> is not being added before the [ld_course_list]. But the content from the shortcode is being loaded.

If I add the ID to the Raw Element and load the CSS and JS manually on the PRO page it works fine. When the default content area is used, the CSS and JS are loaded before the closing </body> tag.

Is there a reason why the code after the return in line 9 would not run on a PRO page, but will on a default WP page?

Hello There,

Thanks for writing in! The Pro editor is using the filter the_content which is also used in the loading the course list. The order of loading the filter could be the reason of this issue.

Could you please wrap the shortcode instead and see if it works?

<div id='ld_course_list'>
[ld_course_list]
</div>

Please let us know how it goes.

@RueNel

Thanks for your suggestion, but that doesn’t change anything other than adding in the DIV on the page manually.

Also interesting is that if I comment out line 16 from the code above, in the page that uses Cornerstone, the content still appears, but when using the WP editor page the content is not displayed.

Hi @designerken,

That code is not from the theme and probably not made or integrated for the cornerstone. The code only assumes the content is just standard content (the_content) and process it. The code could be executed earlier than the builder’s shortcode. But by analyzing the logic from the return line,

return preg_replace( '/(.*\[ld_\w+_list.*)/', '<div id="ld_course_list">$1</div>', $content );

It’s not really a shortcode, because it simply finds '/(.*\[ld_\w+_list.*)/' (eg. [ld_course_list] and similar) and replace it with their preferred content like '<div id="ld_course_list">$1</div>'. It’s not really a shortcode but just string replacement, the real shortcodes which will work in the builder is added through https://codex.wordpress.org/add_shortcode and not by just filtering the_content.

I recommend contacting the plugin author for work-around and create a similar shortcode instead of string replacement.

Thanks!

@Rad

Thanks for the suggestion. Yes you are correct that is just replacing the shortcode string [ld_course_list I believe they are doing it this way because they allow for options to be added to the shortcode like number of columns. So for instance you could write [ld_course_list col=3] and then the code will render a 3 column grid.

I understand the section of code I highlighted is only showing a portion of the over code. But it is part of the issue with the problem I am experiencing. Yes it expecting it to be in a normal WP content editor and replaces the shortcode and wraps it in a DIV and places it back in the content. While I dont agree with it is the way they wrote the code. I will work with them, but they will more than likely say that its not meant to be placed in a page builder.

So for now I am trying to figure out why the CSS and JS are not being loaded on the PRO page form the code I highligted above. It will load in a normal WP editor page.

If I comment out the first return in line 9, then it loads. in the Pro page.

Hi @designerken,

I understand what you mean, but I also should repeat that the problem is indeed the code. Actually, that return is part of the problem as it breaks out of the function when used with Pro. The reason is that the whole pro injects it’s stuff to the_content.

Long story short, you need to change the way it is coded, and also with the standard way of adding shortcodes in WordPress which my colleague mentioned you can have options, and that having the col=3 option is not a good reason to code like the one you added. The standard shortcode system already provides the presentation of options.

We can not be of a help on this matter unfortunately and I am sure you will understand that this is about a 3rd party script which is outside of our support scope. We already mentioned that the script developer should use the standard Shortcode Addition feature of the WordPress.

Thank you for your understanding.

@christopher.amirian

I do understand and I appreciate your teams input so far. I am just trying to find a solution and see if PRO was part of the issue. I guarantee that when I hear from their support team that they come back pointing the finger at you stating that their software works with the default WP editor so PRO must be the issue.

I agree that they have “highjacked” one of their shortcodes instead of updating their software to add the extra options. Basically they wrote a plug-in to output their content as a grid. But use an existing shortcode to do it and are stripping it from the content and wrapping it in a DIV and injecting CSS and JSS to the page.

Hi @designerken,

Yes, they may say that. But they shouldn’t compare standard editor and pro builder. The editor only contains static content that is, of course, replaceable through the filter. But the Pro builder is different, it’s the same rule why sliders, grid,s and other features are needed to be integrated first :slight_smile:

If they can convert that code or add a new code for the proper shortcode then it will surely work :slight_smile:

Thanks!

Well the shortcode itself works, it does produce a list of items.

It’s how they implemented the add-on to convert the list into a grid. They created a separate plug-in (which is fine) but it tries to find the shortcode and strip it out and apply the HTML to it and inject CSS and JS on the page.

So I think it is firing after the PRO builder already has converted the original shortcode to its HTML counterpart, but then in the code mentioned above, to determine if its FALSE, fires the return (since it can no longer find the shortcode). Therefore it never gets to the part about adding in the assets.

Hello @designerken,

Thanks for updating the thread.

I suggest you to please have a word with the plugin developer as the builder captures the assets registered through https://developer.wordpress.org/reference/functions/wp_enqueue_script/ to create proper rendering and to prevent redundancy for every element preview. Now, your code adds its own asset in the middle of the process and the builder is unable to capture it.

It’s like only adding the assets in the middle of filtering the content. And it’s not how the builder works, it has to capture them first then render it, and it’s something we can’t change. I recommend contacting the developer to see if they can add their assets the way it should be added before the main content.

Thanks for understanding.

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