I'm new at this.
I need a shortcode that returns the post id of the post in which the shortcode is inserted.
If someone could provide that it would open the doors of understanding for me :)
Much appreciated!
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI'm new at this.
I need a shortcode that returns the post id of the post in which the shortcode is inserted.
If someone could provide that it would open the doors of understanding for me :)
Much appreciated!
Place the below code to your themes functions.php
or inside your plugin and the [return_post_id]
shortcode will print the post ID.
add_shortcode( 'return_post_id', 'the_dramatist_return_post_id' );
function the_dramatist_return_post_id() {
return get_the_ID();
}
Hope that helps.
Shortcode: Embeddable Post Excerpts
After installing the shortcode (follow steps 1 + 2 below) you can execute it anywhere WordPress accepts shortcodes. To connect to a post, you simply need to enter the post ID you wish to display: