WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Connor Crosby
    Member
    Posted 3 years 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 3 years ago #

    Try

    <?php
    global $post;
    wp_get_shortlink( $post->ID );
    ?>
  3. Connor Crosby
    Member
    Posted 3 years ago #

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

  4. Connor Crosby
    Member
    Posted 3 years 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. Connor Crosby
    Member
    Posted 3 years 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!

  6. Connor Crosby
    Member
    Posted 3 years ago #

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

  7. You're welcome!

  8. stevec828
    Member
    Posted 2 years 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