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

Read More
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?

Related posts

2 comments

  1. 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 );
    }
    
  2. 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]');
    }
    

Comments are closed.