I’m using a shortcode to render a count-up box on my page. To do so, I can add something like [ut_count_up to="1000"][/ut_count_up] in the editor for this particular page. That’s all well as long as the number we’re counting up to is static. Unfortunately, I need to make that number dynamic based on some visitor data. This “visitor data” is collected in a custom shortcode that returns the number I want to count up to. I can easily display this number on its own by adding [visitor-data] in the editor. The problem comes when I want to use that number as value of the “to” attribute of the ut_count_up shortcode. For example, I was expecting this to work:

[ut_count_up to='[visitor-data detail="population"]'][/ut_count_up]

It actually comes pretty close to working as expected in that it does successfully set the number returned by my custom shortcode as the value for the “to” attribute in the ut_count_up shortcode… and the page displays a box with a number that counts up to that value. The problem here is that a stray '] is displayed on the page right after the count-up number. It looks like the closing bracket from my custom shortcode closed the parent shortcode and the trailing characters were left behind to be displayed literally on the page.

What is the correct way to use pass a value generated by a shortcode to another shortcode as a value for a given attribute?

Read more here: WordPress: How to use a nested shortcode to render the value of an attribute in parent shortcode


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: