Graham Barnes
Graham Barnes

Reputation: 235

How can I use shortcodes in visual composer

I am using visual composer and I have made a standard shortcode called 'fieldorigin' in my theme functions file:

add_shortcode( 'fieldorigin', 'origin' );
function origin($atts) {
    //ob_start();
    return "hello";
    //return ob_get_clean();
}

And I was hoping to put this in the standard visual composer 'WP Text - Arbitrary text or HTML' option where I wanted 'hello' to appear: [fieldorigin] in a form field value - it is just a standard html form, name, email message etc.

However when i save my page and view it in the browser it still shows '[fieldorigin]' and not the word 'hello' as shown in my code above.

If I put the shortcode anywhere in the form (not as a field value) or before the form, it outputs 'hello' fine but I would like it as a form input field value.

as you can see from the above I have tried ob_start(); and return ob_get_clean(); but no luck.

Can anyone help, I have also tried the shortcode mapper built into visual composer but again no luck.

Upvotes: 2

Views: 6606

Answers (1)

Azenis
Azenis

Reputation: 77

Try with a regular text block and simply write your shortcode there.

Write the shortcode here, or anywhere else

Upvotes: 3

Related Questions