Forums

[resolved] the_shortlink How to show just link? (9 posts)

  1. ccmovies
    Member
    Posted 1 year ago #

    I am using the <?php the_shortlink(); ?> code and I want to display just the link and not the default text. For example, it will say something like "Blog Post Shortlink" and below it, it will display the shortlink "example.com/?=whatever". How can I do this? Thank you!

  2. Joseph
    Member
    Posted 1 year ago #

    Try

    <?php
    global $post;
    wp_get_shortlink( $post->ID );
    ?>
  3. ccmovies
    Member
    Posted 1 year ago #

    I tried using that code and it does not work. I doesn't show anything.

  4. ccmovies
    Member
    Posted 1 year ago #

    I changed it to the_shortlink and it now shows the post ID, however I would like for it to show the whole link (including example.com?=" or whatever it shows. Thanks!

  5. James
    Happiness Engineer
    Posted 1 year ago #

  6. ccmovies
    Member
    Posted 1 year ago #

    It worked! All I did was copied this code <?php echo wp_get_shortlink(get_the_ID()); ?> and it shows up nicely. Thank you!

  7. ccmovies
    Member
    Posted 1 year ago #

    This code also seems to work if you get rid of get_theID() from inside the parentheses.

  8. James
    Happiness Engineer
    Posted 1 year ago #

    You're welcome!

  9. stevec828
    Member
    Posted 7 months ago #

    Thanks for this guys. I wanted to create a custom RSS feed with the shortlink instead of permalink, used <?php echo wp_get_shortlink(get_the_ID()); ?>, and it worked like a charm.

Topic Closed

This topic has been closed to new replies.

About this Topic