Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: WP.ME Shortlink Generator

  1. #11
    andrea_r's Avatar
    andrea_r is offline WordPress Rockstar
    Join Date
    Jan 2009
    Location
    Eastern Canada
    Posts
    1,325

    Default

    I'm kind of glad they force people to upgrade in order to use it. :)

  2. #12
    Viper007Bond's Avatar
    Viper007Bond is offline Hello World
    Join Date
    Aug 2009
    Location
    Portland, OR, USA
    Posts
    5

    Default

    Quote Originally Posted by andrea_r View Post
    I'm kind of glad they force people to upgrade in order to use it. :)
    It's not artificial, the needed hook just doesn't exist in older versions. :)

  3. #13
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    862

    Default

    Fun bit of code I added to a theme for this:

    In the theme header:
    HTML Code:
    <script language="JavaScript">
    function highlight(field) {
           field.focus();
           field.select();
    }</script>
    In the Loop:
    PHP Code:
    <?php if (function_exists('get_shortlink')) { ?>
    <div><span class="shortlink">Shortlink: 
    <input type='text' 
    value='<?php echo get_shortlink(get_the_ID()); ?>
    onclick='highlight(this);' />
    </span></div>
    <?php ?>
    Result: A text box with the shortlink in it. Click it, it selects the whole thing for easy copy/paste.

  4. #14
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    862

    Default

    Addendum: I was mistaken about shortlink formats. The post-links start with "p". Individual blog links do not. Other than that I was dead on.

    Example:
    My blog: http://wp.me/4uuB
    Post on my blog: http://wp.me/p4uuB-9l

  5. #15
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    862

    Default

    Note: WP 3.0 changed all this. It'll support shortlinks natively, with plugins doing the heavy lifting.

    Default shortlinks will be of the http://example.com/?p=ID format.

    Plugins can override this to make their own shortlink output.

    Functions of use:

    the_shortlink($text = '', $title = '', $before = '', $after = '') - Loop function, outputs the shortlink in the form of an a href link.

    wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) - Returns the shortlink. Can optionally return the shortlink for an item defined by the item id and the context. Allow slugs is for use by plugins only.

    wp_shortlink_wp_head() - inserts link tags into the html head.
    wp_shortlink_header() - inserts link tags into the http header.

    These can be disabled like so, if desired (shouldn't be necessary):
    remove_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
    remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );

    A plugin has two filters it can use to override the shortlink:

    pre_get_shortlink - Happens before default shortlink generation. If this filter gets anything returned to it, then the default stuff gets skipped. Probably should be used by most shortlink plugins.

    get_shortlink - Happens after default shortlink generation. Only should be used to modify default shortlinks.

    Using either of those to modify the shortlink will cause your modification to show up everywhere the shortlink functions are used.

    Example usage:
    PHP Code:
    <?php if (function_exists('wp_get_shortlink')) { ?>
    <div><span class="post-shortlink">Shortlink: 
    <input type='text' value='<?php echo wp_get_shortlink(get_the_ID()); ?>' onclick='this.focus(); this.select();' />
    </span></div>
    <?php ?>
    Shows an input box with the shortlink in it. Clicking the box selects the shortlink for copy/paste.

  6. #16
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    I noticed that short URL link in the new admin panel a few days ago. It looks pretty handy. I often go manually creating those URLs via the post/page ID, but it will be nice to have it right there in front of me from now on.

  7. #17
    andrea_r's Avatar
    andrea_r is offline WordPress Rockstar
    Join Date
    Jan 2009
    Location
    Eastern Canada
    Posts
    1,325

    Default

    This is very very yummy. :)

  8. #18
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    862

    Default

    Quote Originally Posted by Ryan View Post
    I noticed that short URL link in the new admin panel a few days ago. It looks pretty handy. I often go manually creating those URLs via the post/page ID, but it will be nice to have it right there in front of me from now on.
    Yes, perfect example. The Get Shortlink button on the Edit Post page shows the shortlink easily.

    Install the WordPress.com Stats plugin, and you'll see it change to a wp.me link automatically. That's how the plugin support works.

  9. #19
    andrea_r's Avatar
    andrea_r is offline WordPress Rockstar
    Join Date
    Jan 2009
    Location
    Eastern Canada
    Posts
    1,325

    Default

    Speaking of the wp.com stats plugin, I just noticed a new tab in the stats are called "Humanize".

  10. #20
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    862

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •