WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Tweetbacks] [Patch] Find non-rewritten permalinks (3 posts)

  1. thefluffanutta
    Member
    Posted 5 years ago #

    I wanted Tweetbacks to also find links that used WordPress' default URLs, as if the Permalinks setting hadn't been changed. For example: mysite.com/blog/?p=123. I did this so that my 'Tweet This' links could be shorter without using a 3rd-party service.

    Here's the patch for tweetbacks.php version 1.5:
    [modification of function yoast_get_tweetback()]

    *** 505,510 ****
    --- 505,511 ----
            require_once(ABSPATH . WPINC . '/rss.php');
    
            $permalink = get_permalink($post_id);
    +       $defaultlink = get_option('home') . '/?p=' . $post->ID;
    
            $shorturls = get_post_meta($post_id,"shorturls",true);
            $oldshorturls = $shorturls;
    ***************
    *** 524,529 ****
    --- 525,535 ----
                    $shorturls['permalink'] = $permalink;
            }
    
    +       // Add the raw permalink of the post itself, e.g. /blog/?p=123
    +       if (!isset($shorturls['defaultlink'])) {
    +               $shorturls['defaultlink'] = $defaultlink;
    +       }
    +
            if (!isset($shorturls['tinyurl'])) {
                    $result = $snoopy->fetch("http://tinyurl.com/api-create.php?url=".$permalink);
                    if ($result && strpos($snoopy->response_code,"200") !== false && $snoopy->results!="" && strpos($snoopy->results,"http://tinyurl.com") === 0) {

    Here's what I put in comments.php for my theme:

    <a href="http://twitter.com/home?status=<?php the_title_attribute();?>:+<?php echo get_option('home');?>/%3Fp%3D<?php the_ID(); ?>">Tweet this post</a>

    Works a treat.

    :)

  2. thefluffanutta
    Member
    Posted 5 years ago #

    Sorry, made a typo on first modified line. Should have been this:

    + $defaultlink = get_option('home') . '/?p=' . $post_id;

  3. rickybuchanan
    Member
    Posted 5 years ago #

    This would be really useful to have in the default package, as for those with short hostnames they're like pre-shortened URLs with no service needed. Joost?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags