Dkikas
Dkikas

Reputation: 23

Wordpress shortcode rendering

I made a basic shordcode

function map_test(){

    $map_render = '<p>test</p>';
    return $map_render;
}

add_shortcode( 'map_shortcode', 'map_test' );

and the shortcode is created and all works fine until i do

if ( shortcode_exists( 'map_shortcode' ) ) {
    echo do_shortcode('[map_shortcode]');
}

i get the

Test

rendered but after the element there is also a number 1 with double quotes

So i was wondering why is that "1" there and what made it render, also how to remove it?

Upvotes: 1

Views: 53

Answers (2)

Dkikas
Dkikas

Reputation: 23

So the solution was to remove the 'echo' from echo do_shortcode, and the "1" is removed, ty all for your time.

if ( shortcode_exists( 'map_shortcode' ) ) {
  do_shortcode('[map_shortcode]');
}

Upvotes: 1

Venkat
Venkat

Reputation: 347

Try the following to check short code existence and remove the same:

function shortcode_exists( $tag ) {
    global $shortcode_tags;
    return array_key_exists( $tag, $shortcode_tags );
}

Upvotes: 2

Related Questions