Forums

[resolved] Shortcode not displaying where I am typing it (2 posts)

  1. ridesign
    Member
    Posted 3 years ago #

    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.

  2. freak_on_a_leash
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags