WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Displaying post ID within shortcode php in template (3 posts)

  1. PinkishHue
    Member
    Posted 2 years ago #

    Hi folks,

    In my single.php template under the post content I have the code for a shortcode with some html between the opening and closing parts of the shortcode.

    Within the html I would like to display the post ID, however the usual method '<?php the_ID(); ?>' doesn't seem to be working. There's probably a simple way to get around this - can anyone advise me?

    Example:

    '<?php echo do_shortcode('[hide-this-part]

    this is where I put my html...blablabla...

    [/hide-this-part]'); ?>'

    This is before the end of the loop.

    Thanks a lot for any help you can give me.

    Jo

  2. PinkishHue
    Member
    Posted 2 years ago #

    Have re-posted this question in the themes & templating section as I realised this maybe wasn't the best place for it. Apologies for the double post.

    Here is the other thread: http://wordpress.org/support/topic/displaying-post-id-within-shortcode-php-in-template-1?replies=1

    [please stay with your current topic - it does not matter too much in what sub forum you are posting. other, duplicate thread removed]

  3. PinkishHue
    Member
    Posted 2 years ago #

    I found the answer to this, I think at first I was not searching for the right terms, but when I searched php inside echo things made more sense (thanks to this post - http://wordpress.org/support/topic/php-inside-php-echo)

    Posting the solution here in case anyone is interested:

    <?php echo do_shortcode('[hide-this-part]
    this is where I put my html...blablabla...
    '. the_id() .'
    [/hide-this-part]'); ?>

    I also had trouble having the post ID generated as part of the item name of a Paypal button WITHIN the shortcode area, and that worked by using:

    . get_the_ID() .

    instead of . the_id() .

    Will mark this as resolved now.

Topic Closed

This topic has been closed to new replies.

About this Topic