3

I am using this plugin: http://wordpress.org/extend/plugins/worldcurrency/

Shortcode syntax:

[worldcurrency cur="EUR" value="25"] 

However, I'm using Advanced custom fields and the shortcode for custom fields is not being executed within the shortcode for worldcurrency.

[worldcurrency curr="[acf field="fl_currency"]" value="25"]

Any remedies here?

Update
I think I need to be using the

add_filter('xx','do_shortcode');

somehow?

4

3 Answers 3

1

I haven't tried this, but you could try pseudo-changing the priority of your shortcode hook.

Basically, you force your shortcode to execute before it would normally. That link shows how to execute your shortcode separately - and, more importantly, before - the other shortcodes get implemented.

This works by caching and temporarily removing all existing shortcodes, executing yours, then reestablishing the other shortcodes.

3
  • wouldn't this slow down the web page speed significantly? Feb 5, 2013 at 2:14
  • As I said, I haven't tried it, but I don't see anything obvious in the example code that would make a significant difference in speed. As far as I can tell, it simply copies the variable containing the preexisting shortcodes (probably just a simple array), removes them en masse (which shouldn't be a significant slow-down) using remove_all_shortcodes(), creates your shortcode, then copies the old shortcodes variable back.
    – akTed
    Feb 5, 2013 at 2:47
  • Just found where WP does the same thing for the [embed] shortcode, since it too needs to run earlier. In WP 3.5, in wp-includes/class-wp-embed.php line 50 is the method run_shortcode(). The example I linked too is nearly identical (including code comments). So it would appear this is The WordPress Way to do it.
    – akTed
    Feb 5, 2013 at 3:03
0

If you look at the ACF shortcode in source (api.php), it just uses the API function get_field on the shortcode's field attribute.

If you look at the world currency shortcode in source (worldcurrency.php), it outputs a span with the worldcurrency class and a couple of custom attributes, which then get converted on the user side via javascript.

You could probably write your own shortcode that combines the two, using the output of world currency with ACF's get_field to fetch the attributes from fields you specify.

1
  • Sounds promising but i dont have the skills to do this on my own I am afraid. Feb 5, 2013 at 2:15
0

My answer involves changing the coding of world currency plugin.
Then write the shortcode like this:

[worldcurrency value="25"][acf field="fl_currency"][/worldcurrency]

In the code for the currency plugin, the value of the custom field will be available through the $content field.
Then just set the curr field to $content and you should be good to go.

2
  • the value 25 is going to be a custom field as well so this makes things more difficult. Feb 4, 2013 at 19:38
  • Making changes in plugins isn't encouraged. When you update the plugin the changes that were made would be overwritten. Jul 8, 2013 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.