The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

WP Bitly
[resolved] [Plugin: WP Bit.ly] Display actual link (5 posts)

  1. bschnure
    Posted 6 years ago #

    I know you can change the default text from "This is the short link" to whatever you want, but I don't see a way to have it just display the actual link without other text.

    The old version in 2.9.2 did this by default, but the new version for 3.0.1 doesn't.

    I basically want to mimic the old output (which you can see in the deprecated.php file):

    $text = $wpbitly_link;
    $wpbitly_print = '<a href="' . $wpbitly_link . '" rel="shortlink" class="wpbitly shortlink">' . $text . '</a>';

    The display text ($text) is set to the link itself ($wpbitly_link).

    So how do I use the parameters in the_shortlink() to do this?

  2. bschnure
    Posted 6 years ago #

    I was able to do it by editing wp-includes/link-template.php. I changed:

    $link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>';


    $link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $shortlink . '</a>';

    I don't like having to edit core files to do this kind of stuff, since you always have to remember to make the changes again whenever you upgrade.

    Is there an easier way to do this in a cleaner fashion using the_shortlink()?

  3. Mark Waterous
    Plugin Author

    Posted 6 years ago #

    The easiest method to do this would be the following;

    the_shortlink( wp_get_shortlink() );

    Alternatively if you want to ensure that any occurrence of the_shortlink() will default the text to the actual short link itself, you could do the following;

    add_filter( 'the_shortlink', 'my_shortlink', 10, 4 );
    function my_shortlink( $link, $shortlink, $text, $title )
    	return '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $shortlink . '</a>';


  4. Piet Bos
    Posted 5 years ago #


    I would like to use the value of the link (so just the text, not wrapped in <a href=""></a>.

    I have tried to play around with the last line of your filter, to delete the link-part of it, but that only results in a totally broken function as it asks for 4 arguments. I have also had a long look at line 192-224 of the wp-bitly file, but I cannot figure it out.

    Is there a simple way to make this possible?

  5. Piet Bos
    Posted 5 years ago #

    ok figured it out with the very helpful article over at Otto: http://ottopress.com/tag/wp_get_shortlink/

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Bitly
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic