Search code examples
phpwordpressshortcodevisual-composer

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?


Solution

  • 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"]