Skip Navigation

[Resolved] Shortcodes

This support ticket is created 3 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 2 replies, has 2 voices.

Last updated by tomerH 3 years, 5 months ago.

Author
Posts
#1831053

Hi,

Please have a look here: hidden link
How can I do something similar with toolset?

In my case, instead of using facebook feed plugin I use stock market plugin but the behavior is identical.

No please have a look here:
hidden link

I use many shortcodes (~10) for every post that are based on an external stock market plugin.

Every post (=company) has a custom field called "ticker". For example, in Microsoft post the custom field "ticker" is MSFT. For Booking (hidden link) the ticker is "BKNG"

I basically want to be able to add the full shortcode to the shortcode block in the content template and to add the "ticker" custom field and put it inside the relevant area in the shortcode. This way I can change/edit the shortcodes in main source and all the posts will adjust automatically.

For example, in the shortcode:
[stock_market_widget type="accordion" template="info" color="#5679FF" assets="MSFT" start_expanded="true" style=".smw-accordion-container.smw-accordion-container-expanded > .smw-accordion-header > .smw-flexbox > .smw-flexbox { opacity: 0; }" api="yf"]

I want that: assets=@ticker (as you see in mylisting's theme example).

Hope I made my request clear..

Thanks

#1831793

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

You want to be able to use the stock_market_widget shortcode in a template where the assets attribute is set dynamically according to the ticket custom field for the post being displayed with the template.

The problem here is that WordPress does not support nested shortcodes or shortcodes as attributes of other shortcodes. Toolset does, using a bespoke system, but only for its own shortcodes, not universally.

You'll need to code a solution.

You can register your own custom shortcode to use in place of the stock_market_widget shortcode.

If needs be you can pass the values for the same attributes as attributes of your custom shortcode, or if they do not vary you can hardcode them in your custom shortcode.

For the assets attribute, you can retrieve the id of the current post using the global $post object, then get the assets custom field value using get_post_meta. You then build a string replicating the original stock_market_widget shortcode where you set the assets attribute with the custom field value you retrieved, and then pass this assembled string through the do_shortcode function and return the resulting string.

See the following links for more info:

https://developer.wordpress.org/plugins/shortcodes/
https://developer.wordpress.org/reference/functions/get_post_meta/
https://developer.wordpress.org/reference/functions/do_shortcode/

Ask for help if you get stuck, but please be aware that writing such custom code for a non-Toolset feature is outside the scope of support.

#1831911

Ok, thanks Nigel for the information!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.