WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#9171 closed defect (bug) (invalid)

Shortcodes not outputting correctly

Reported by: ridesign Owned by:
Milestone: Priority: high
Severity: normal Version: 2.7
Component: General Keywords: shortcode, shortcodes
Focuses: Cc:

Description

When using the below shortcodes function, the post id does not output where the shortcode is typed in the post page. The post id is displayed right at the start of the post section.

function shortcode_id() {

the_ID();

}
add_shortcode('id', 'shortcode_id');

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

What is typed in the post page:
This is a good post. This is Post ID:[id]

Change History (3)

comment:1 ridesign5 years ago

  • Keywords shortcode added

comment:2 ridesign5 years ago

  • Cc ridesign added

comment:3 jamescollins5 years ago

  • Milestone 2.7.2 deleted
  • Resolution set to invalid
  • Status changed from new to closed

Your shortcode_id)() function is supposed to return a string of content, rather than echo'ing out the content directly.

the_ID() echo's the ID.

In your case your shortcode_id() should probably return get_the_ID() instead.

See http://codex.wordpress.org/Shortcode_API for more information.

Note: See TracTickets for help on using tickets.