Support » Plugins » Shortcode not displaying where I am typing it

  • Resolved ridesign

    (@ridesign)


    I am trying to use short code to display the post id inside a post, however when I use [id] it is showing the post ID at the start of the post of the post content, not where I have typed it.

    The shortcode I am using, I have placed this in the plugin folder.

    function shortcode_id() {
       $id = the_ID();
    echo $id;
    }
    add_shortcode('id', 'shortcode_id');

    What displays on the post page: 10741This is a good post. This is Post ID:

    I also tried: echo the_ID(); but it doesn’t work either.

Viewing 1 replies (of 1 total)
  • freak_on_a_leash

    (@freak_on_a_leash)

    I just noticed here that you can’t use echo when returning the content of a shortcode. you have to use ‘return’ as specified in the shortcode manual.

Viewing 1 replies (of 1 total)
  • The topic ‘Shortcode not displaying where I am typing it’ is closed to new replies.