Reputation:
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
Reputation: 481
Use return instead of echo
function echo_first_name(){
return $_GET['first_name'];
}
add_shortcode( 'first_name', 'echo_first_name' );
Upvotes: 0
Reputation: 4148
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
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