2

I am using Visual Composer and have entered HTML into a Raw HTML element for a custom pricing table - I now would like to be able to use the World Currency plugin to show prices in different currencies.

The shortcode for World Currency is:

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

When I enter this into the Raw HTML it shows up as text exactly as above.

If I enter it using:

<?php echo do_shortcode('[worldcurrency curr="EUR" value="25"]'); ?>

nothing shows and upon checking the source the whole echo is commented out in the HTML.

I also tried entering the HTML into a text block but things like tooltips no longer work properly and when entered as text rather than visual I lose the ability to edit the text totally.

Is there a way of using the shortcode within Raw HTML or another element within Visual Composer which will let me use the shortcode and HTML?

1 Answer 1

3

When you look at how do_shortcode() actually works, then it's this:

do_shortcode( $content )

Where $content is defined as the following:

(string) Content to search for shortcodes

What you are trying to do is to echo what the shortcode does, leading to a false assumption. There is no magic function discovering your shortcode. The shortcode simply is a callback (a function or a method) attached to some string that you can put between square brackets in full text content. When the content is read during the livecycle/runtime and is found, then the attached callback is executed in its place. Pretty much the same as what happens with actions and filters. So

 add_shortcode( 'bartag', 'bartag_func' );

allows this

 [bartag foo="bar"]

where bartag_func is the callback. For e.g.:

function bartag_func( $atts )
{
    $args = shortcode_atts( array(
        'foo' => 'no foo',
        'baz' => 'default baz',
    ), $atts );
    return "foo = {$args['foo']}";
}

What you are (or should be) searching for is where the shortcode gets added with add_shortcode(). Then just find the callback (for e.g. the bartag_func()) and execute or echo it

echo bartag_func();

That's it.

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