user6078343
user6078343

Reputation:

Visual Composer: Custom Shortcode Not Working

The following is the shortcode I created in functions.php:

function echo_first_name() {
    echo $_GET['first_name'];
}
add_shortcode( 'first_name', 'echo_first_name' );

And I'm entering the following into my Visual Composer editor:

['first_name']

This produces no result, even when using the Visual Composer shortcode mapper.

Does anybody know why this isn't working? Do I have to register it as another type of shortcode for Visual Composer to be able to access it?

Upvotes: 1

Views: 2215

Answers (3)

Chinou
Chinou

Reputation: 481

Use return instead of echo

function echo_first_name(){
return $_GET['first_name'];
}
add_shortcode( 'first_name', 'echo_first_name' );

Upvotes: 0

Ankur Bhadania
Ankur Bhadania

Reputation: 4148

For Create Short code

if you want to add short code in editor then Used return instead of echo

function echo_first_name() {
    return $_GET['first_name'];
}
add_shortcode( 'first_name', 'echo_first_name' );

Used Short Code Like

[first_name] 
If you want to pass the value In shortcode
function echo_first_name( $atts ) {
    $a = shortcode_atts( array(
        'firstname' => '',
    ), $atts );

    return "First Name= {$a['firstname']}";
}
add_shortcode( 'first_name', 'echo_first_name' );

Used Short Code Like

[first_name firstname="test"]

Upvotes: 0

Piyush Dhanotiya
Piyush Dhanotiya

Reputation: 579

You are passing a $_GET['firstname'] in the shortcode function from where you are passing this in URL or from any other place. Please check it is coming or not. Or if you want to test your shortcode is working or not use beloww code it will work.

function echo_first_name() {
    return 'testing the shortcode';
}

add_shortcode( 'first_name', 'echo_first_name' );

Upvotes: 0

Related Questions