Links in Tweets

resolved (20 posts) (3 voices)

  1. markb1439
    Member

    Hi,

    I'm wondering if links in Tweets can be presented better in all the themes? For example, if there is a link in a tweet, you should be able to click that link and go to the URL in question. However, instead, you go to the tweet on the Twitter page, and then you have to click the link there to go to the featured URL. It is much more efficient to click the link once and arrive at the destination, rather than having to click twice. It's redundant to click on a tweet and then just go to the same tweet on Twitter.

    Is this possible?

    Thanks,

    Mark

    Posted 9 months ago #
  2. Elliott
    Support

    Hello markb1439,

    I haven't tested this yet but open up /wp-content/themes/dejavu/lib/functions/twitter.php and comment out line 105 to see if that works for you.

    $twit = substr(strstr( $twit, ': ' ), 2, strlen( $twit ));

    Posted 9 months ago #
  3. markb1439
    Member

    That didn't work. :-(

    However, below that line I see several lines of code for converting URLs to links and such. They are all commented out too.

    UPDATE: When I comment out the line you mentioned, AND the few lines below that, it works.

    Thanks!

    Mark

    Posted 9 months ago #
  4. markb1439
    Member

    Sorry, I mis-spoke. The first line should NOT be commented out. The other lines I mentioned should be commented out. That segment of code should look like:

    function mysite_filter_tweet( $twit ) {
    
    	# Remove the preceding 'username: '
    	$twit = substr(strstr( $twit, ': ' ), 2, strlen( $twit )); 
    
    	# Specifically for non-English tweets, converts UTF-8 into ISO-8859-1
    	//$twit = iconv( 'UTF-8', 'ISO-8859-1//TRANSLIT', $twit );
    
    	// Convert URLs into hyperlinks
    	$twit = preg_replace("/(http:\/\/)(.*?)\/([\w\.\/\&\=\?\-\,\:\;\#\_\~\%\+]*)/", "<a href=\"\\">\</a>", $twit);
    	// Convert usernames (@) into links
    	$twit = preg_replace("(@([a-zA-Z0-9\_]+))", "<a href=\"http://www.twitter.com/\\1\">\</a>", $twit);
    	// Convert hash tags (#) to links
    	$twit = preg_replace('/(^|\s)#(\w+)/', '\1<a href="http://search.twitter.com/search?q=%23\2">#\2</a>', $twit);
    
    	return $twit;
    }
    Posted 9 months ago #
  5. Elliott
    Support

    Glad you got it worked out markb1439 and thanks for posting your solution.

    Posted 9 months ago #
  6. markb1439
    Member

    Hi,

    Actually, I've realized that it isn't working fully. I don't know if I missed something, or if it's different with a newer version of the theme.

    Can you suggest code to achieve the desired results (clickable username, link, tweet time, etc.)? And it would be great if those items would open in a separate window.

    Thanks,

    Mark

    Posted 8 months ago #
  7. Elliott
    Support

    You should be able to do the same thing in our new framework. The file is /wp-content/themes/[your_theme]/lib/functions/twitter.php.

    Let us know if that works for you markb1439.

    Posted 8 months ago #
  8. markb1439
    Member

    Hi,

    I tried it but there were various issues. First, the username and any URLs used a separate line (which I solved by modifying a line in shortcodes.css). But, another issue is that the first part of the tweet is still an active link (up to the point where any username, URL or hashtag appears). And I can't figure out how to make the usernames and hashtags open in a new window.

    I think it all has something to do with the few lines of code above the section we mentioned, as those lines seem to establish the tweet format. But I haven't been able to adjust that code properly to achieve the desired results. :-(

    Thanks,

    Mark

    Posted 8 months ago #
  9. Elliott
    Support

    Uncommenting these lines does not work for you?

    // Convert URLs into hyperlinks
    $twit = preg_replace("/(http:\/\/)(.*?)\/([\w\.\/\&\=\?\-\,\:\;\#\_\~\%\+]*)/", "<a href=\"\\">\</a>", $twit);
    // Convert usernames (@) into links
    $twit = preg_replace("(@([a-zA-Z0-9\_]+))", "<a href=\"http://www.twitter.com/\\1\">\</a>", $twit);
    // Convert hash tags (#) to links
    $twit = preg_replace('/(^|\s)#(\w+)/', '\1<a href="http://search.twitter.com/search?q=%23\2">#\2</a>', $twit);

    If possible then send us a link to your page so we can take a closer look.

    Posted 8 months ago #
  10. markb1439
    Member

    Hi,

    Well, it works but not perfectly. Here is a link for the time being, although it might come down at some point:

    http://cusites.com/sample-page/

    Note that the first few words of the tweet (up to the first linked username or other item) are still an active link. In addition, I need the linked usernames, URLs and such to open in a new window.

    Thanks,

    Mark

    Posted 8 months ago #
  11. Elliott
    Support

    You can get them to open up in a new window by adding target = "_blank" to the anchors like so,

    // Convert URLs into hyperlinks
    $twit = preg_replace("/(http:\/\/)(.*?)\/([\w\.\/\&\=\?\-\,\:\;\#\_\~\%\+]*)/", "<a target = \"_blank\" href=\"\\">\</a>", $twit);
    // Convert usernames (@) into links
    $twit = preg_replace("(@([a-zA-Z0-9\_]+))", "<a target = \"_blank\" href=\"http://www.twitter.com/\\1\">\</a>", $twit);
    // Convert hash tags (#) to links
    $twit = preg_replace('/(^|\s)#(\w+)/', '\1<a target = "_blank" href="http://search.twitter.com/search?q=%23\2">#\2</a>', $twit);
    Posted 8 months ago #
  12. markb1439
    Member

    Ah, thank you. I had tried various code to do that, but I was not successful. Thanks for showing me the right way. :-)

    I am still trying to figure out how to make the first few words NOT be a link. I can probably figure that one out.

    Thanks,

    Mark

    Posted 8 months ago #
  13. Elliott
    Support

    I think the link you are seeing is the actual tweet. Try finding lines 80 - 83,

    $out .= '<a class="tweet target_blank" href="' . esc_url( $item->get_permalink() ) . '">';
    $out .= mysite_filter_tweet( $item->get_title() );
    $out .= sprintf( __( '<small> (%1$s&nbsp;ago)</small>', MYSITE_TEXTDOMAIN ), mysite_relative_time(strtotime( $item->get_date() ) ) );
    $out .= '</a>';

    And change it like so,

    $out .= mysite_filter_tweet( $item->get_title() );
    $out .= sprintf( __( '<small> (%1$s&nbsp;ago)</small>', MYSITE_TEXTDOMAIN ), mysite_relative_time(strtotime( $item->get_date() ) ) );
    Posted 8 months ago #
  14. markb1439
    Member

    Thank you for the great support, as usual!

    Posted 8 months ago #
  15. hylidix
    Member

    I also need to display links in tweets in the twitter footer widget. I tried the solution above and it's not working for me. I'm using infocus 2.3. Here is the code from my twitter.php file:

    function mysite_filter_tweet( $twit ) {
    
    	# Remove the preceding 'username: '
    	$twit = substr(strstr( $twit, ': ' ), 2, strlen( $twit ));
    
    	# Specifically for non-English tweets, converts UTF-8 into ISO-8859-1
    	//$twit = iconv( 'UTF-8', 'ISO-8859-1//TRANSLIT', $twit );
    
    	// Convert URLs into hyperlinks
    	$twit = preg_replace("/(http:\/\/)(.*?)\/([\w\.\/\&\=\?\-\,\:\;\#\_\~\%\+]*)/", "<a target = \"_blank\" href=\"\\">\</a>", $twit);
    	// Convert usernames (@) into links
    	$twit = preg_replace("(@([a-zA-Z0-9\_]+))", "<a target = \"_blank\" href=\"http://www.twitter.com/\\1\">\</a>", $twit);
    	// Convert hash tags (#) to links
    	$twit = preg_replace('/(^|\s)#(\w+)/', '\1<a target = \"_blank\" href="http://search.twitter.com/search?q=%23\2">#\2</a>', $twit);
    
    	return $twit;
    }

    I uncommented the lines needed to convert the links and added the target tags. While the links do work, the footer widget gets messed up. Basically, it looks like there is a line break after each link type and each link gets a callout bubble bullet. Example:

    Each tweet should look like the example page with one callout bubble bullet for each tweet and the tweet text displaying with no line breaks.
    Can you help me get this working?

    Attachments

    1. twitwidget.jpg (35.9 KB, 1 downloads) 5 months old
    Posted 5 months ago #
  16. Elliott
    Support

    Hello hylidix,

    It should be the same in version 2.3. Send us a link to your site so we can take a closer look.

    Posted 5 months ago #
  17. hylidix
    Member

    The site is on a local installation, not live on the web, so I can't post a link. The picture says it all.
    (I substituted dummy text because those are a client's live tweets.)

    The links in each tweet work, but can you see the line breaks inserted after each link?
    I changed lines 409 and 410 in style.css to remove the extra callout bubble bullets:

    Before

    .mysite_twitter_widget li {background:none;padding-left:0;}
    .mysite_twitter_widget a {background:url(images/shortcodes/sprites/custom_sprite_dddddd.png) no-repeat -380px -239px;padding-left:26px;}

    After

    .mysite_twitter_widget a {background:none;padding-left:0;}
    .mysite_twitter_widget li {background:url(images/shortcodes/sprites/custom_sprite_dddddd.png) no-repeat -380px -239px;padding-left:26px;}

    That leaves the unwanted line breaks. The whole line, including whitespace, is the link - illustrated in the second tweet by the yellow box. Could the way the PHP code (see previous post) filters the tweet links be causing this? Any ideas on how to remove the line breaks?

    The second tweet should look like this:

    Attachments

    1. twitwidget3.jpg (21.4 KB, 0 downloads) 5 months old
    2. twitwidget2.jpg (51.7 KB, 0 downloads) 5 months old
    Posted 5 months ago #
  18. Elliott
    Support

    I think it's more of a CSS issue. Try this,

    #footer li a { display: inline-block !important; }

    Let us know when you go live and we'll take a closer look.

    Posted 5 months ago #
  19. hylidix
    Member

    Thanks!
    I used the following CSS:

    .mysite_twitter_widget li a {display: inline-block !important; }

    so it only applies to the twitter widget. Applying that statement to the entire footer causes undesired effects in other footer links, namely navigation/menu widgets. It makes the horizontal lines that should span the entire row between each link shrink to the width of the link.

    Posted 5 months ago #
  20. Elliott
    Support

    Glad you got it sorted, let us know if you have any other questions.

    Posted 5 months ago #

Reply

You must log in to post.

Construct WordPress Theme
Construct wordpress theme
Myriad WordPress Theme
Myriad wordpress theme
Method WordPress Theme
Method wordpress theme
Fusion WordPress Theme
Fusion wordpress theme
Elegance WordPress Theme
Elegance wordpress theme
Echelon WordPress Theme
Echelon wordpress theme
Dejavu WordPress Theme
Dejavu wordpress theme
Modular WordPress Theme
Modular wordpress theme