Skip Navigation

[Resolved] Shortcode displaying instead of shortcode content

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by davidR-12 1 year, 11 months ago.

Assisted by: Waqar.

Author
Posts
#2505535

Here you can see the shortcodes being displayed instead of the content that the shortcode generates: hidden link PASSWORD: cucumber

This page is generated by a Content template. The shortcode is being displayed by pulling in a user field using a second shortcode provided by Memberpress. If I add the shortcodes you can see on the page manually to the content template, they display the content as desired, as you can see for the Twitter feed. I can see the shortcodes pulled in form the user field have inverted commas around them for some reason.

Regards,

David

#2505923

Hi David,

Thank you for contacting us and I'd be happy to assist.

It looks like the second shortcode from Memberpress is showing the field's content as it is as a text value. And since no content filters are being applied to that text value, the inner shortcode is not getting expanded into the relevant output.

To overcome this, you can register a third custom shortcode, which:
- first gets the value from the user field, and then
- apply the WordPress 'the_content' filter to it ( ref: https://developer.wordpress.org/reference/hooks/the_content/ ), and then
- return that final expanded output

You'll find the example of such a custom shortcode in this forum reply:
https://toolset.com/forums/topic/since-the-last-update-the-shortcode-i-placed-in-my-article-template-doesnt-work/#post-2307591

I hope this helps and please let me know if you need any further assistance with this.

regards,
Waqar

#2506213

This works for a single one but when I create multiple shortcodes, it will only display the first one. Here is my code:

add_shortcode('show-twitter-shortcode-output', 'show_twitter_shortcode_output_fn');
function show_twitter_shortcode_output_fn() {
    ob_start();
    $content =  do_shortcode("[mepr-account-info field='mepr_twitter_feed_shortcode']");
    echo apply_filters( 'the_content', $content );  
    return ob_get_clean();
	}

add_shortcode('show-facebook-shortcode-output', 'show_facebook_shortcode_output_fn');
function show_facebook_shortcode_output_fn() {
    ob_start();
    $content =  do_shortcode("[mepr-account-info field='mepr_facebook_feed_shortcode']");
    echo apply_filters( 'the_content', $content );  
    return ob_get_clean();
	}

If I add the twitter shortcode and the facebook shortcode, I get 2 twitter feeds (Its running the twitter code twice even though I am using 2 different shortcodes). If I have the Facebook shortcode on its own then it works.

I need to run multiple shortcodes on a single page to create multiple feeds. Why is it doing this?

#2506711

Thanks for writing back.

I'm not exactly sure why the output of one shortcode is affected by the use of another one. But, I was able to make this work, using a slightly different approach.

Instead of registering separate custom shortcodes for each social field, you can register just one common shortcode, which can process the shortcodes enclosed within its opening and closing tags:


function show_processed_shortcode_func( $atts, $content = null ) {
	ob_start();
	$new_content = apply_filters( 'the_content', $content );
	echo apply_filters( 'the_content', $new_content );
	return ob_get_clean();
}
add_shortcode( 'show_processed_shortcode', 'show_processed_shortcode_func' );

Once this shortcode has been registered, you can use it for different social fields, like this:

Twitter:


[show_processed_shortcode][mepr-account-info field='mepr_twitter_feed_shortcode'][/show_processed_shortcode]

Facebook:


[show_processed_shortcode][mepr-account-info field='mepr_facebook_feed_shortcode'][/show_processed_shortcode]

#2508071

Hi Waqar,

Thats brilliant, thank you. Works like a dream.

Warm regards,

David