Twitter Widget Pro
[resolved] Removing URL Shortening (2 posts)

  1. dustamaphone
    Posted 3 years ago #

    Hello! I really like the widget. I am wondering if I can easily remove the URL shortening? I have a client who frequently tweets their site's URL and it doesn't make as much sense to see the shortened version in the widget.

    Thank you!


  2. Aaron D. Campbell
    Plugin Author

    Posted 3 years ago #

    It's all possible with the existing filters, but will take some code to do it and probably an API that unshortens URLs (there are quite a few of these). Here's some code to get you started in the right direction:

    function range_unshorten_urls( $attributes ) {
    	if ( false === strpos( $attributes['href'], 'twitter.com' ) ) {
    		$request_url = add_query_arg( array( 'r' => $attributes['href'], 't' => 'json' ), 'http://api.unshort.me/' );
    		$url_info = json_decode( wp_remote_retrieve_body( wp_remote_get( $request_url ) ) );
    		if ( $url_info && ! empty( $url_info->resolvedURL ) )
    			$attributes['href'] = $url_info->resolvedURL;
    	return $attributes;
    add_filter( 'widget_twitter_link_attributes', 'range_unshorten_urls' );

    That will expand the href of the link. You'll need to do something similar using the 'widget_twitter_link_text' filter expand the text for the link as well. Then you'll REALLY want to add some caching so you're not processing all these links every single time. I recommend using the TLC Transients included with Twitter Widget Pro.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Twitter Widget Pro
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic