Shortcode Plugin to dynamically build a shortcode via `do_shortcode` not working

Basically I want to create a plugin that provides a shortcode for use anywhere.
This plugin will query the user’s preferences and render another shortcode/plugin with proper settings (to cater content). Currently the do_shortcode(‘[sub-shortcode]’) does not process the sub-shortcode and renders the plain text.

Plugin

<?php
/**
* Plugin stuff……
*/

function my_shortcode($atts = [], $content = null)
{
// Query and dynamically set categories
return ‘Testing: ‘.do_shortcode(‘[cm_rss_aggregator category=ex1,ex2]’);
}

add_shortcode(‘example’, ‘my_shortcode’);
?>

On page:

[example]

Renders:

Testing: [cm_rss_aggregator category=ex1,ex2]

Expected:

CM RSS Aggregator to be renedered

This is but one example that I’ll have wrapping such shortcodes – seemed the easiest as en example.
I’ve tried with other basic shortcodes like to no luck.
Also tried with .
Basically trying what’s shown on https://codex.wordpress.org/Shortcode_API#Enclosing_vs_self-closing_shortcodes but dynamically produce the $content.

Any help would be greatly appreciated.

Read more here:: Shortcode Plugin to dynamically build a shortcode via `do_shortcode` not working

Leave a Reply

Your email address will not be published. Required fields are marked *