Support » Plugin: WP to Twitter » From YOURLS to WP to Twitter

  • Resolved gerobe



    I used to work with the plugin YOURLS to Twitter, which did three things when publishing a post:

    1. Shorten the url with YOURLS
    2. Insert the short url as <link rel='shortlink' href="http://short.url"/> in the html-head
    3. post it to twitter

    Unfortunately 3. was removed by the author of the plugin, which made in useless for me.

    So I looked for other plugin and found this great plugin WP to Twitter, which even supports YOURLS.

    But it seems it only supports the shortener itself and does not insert the rel='shortlink' into the post. YOURLS to twitter used the custom field yourls_shorturl to store the shortlink in the post-data.

    But I just made a test and installed both plugins (WP to Twitter and the new YOURLS-Plugin without Twitter-Option). The result was, that after publishing a post, there were two entries for the same URL in the YOURLS-database with to different short-urls. Normally it is not possible to enter the same url twice in YOURLS, but it seems, the access of the two plugin was nearly at the same time and YOURLS was not able to block the double-entry.

    So my question is: How can I use WP to Twitter and place the short url in the head of my html-code?


Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Joe Dolson


    Well, the simplest solution would probably be to add this code to the meta section of your header.php template file:

    if ( get_post_meta( $post_id, '_wp_jd_yourls', true ) ) {
        echo "<link rel='shortlink' href='".get_post_meta( $post_id, '_wp_jd_yourls', true )."' />";

    That just grabs the post meta saved YOURLS link from WP to Twitter and places it in the head of your document. This won’t catch anything saved by your old YOURLS plug-in, however.

    Thank you, Joe, for the fast reply!

    These are good news, that WP to Twitter also stores the short-url in a custom field. So I can alter your code and look also for the “old” value of the YOURLS-Plugin, display it like in your proposal or check if the post has the new variable _wp_jd_yourls stored.

    So post with the new and the old plugin will have their short-link displayed.

    Another solution might be to replace the old variable name with the new one inside the SQL-database.

    This helped me a lot!

    Thank you!


    For those who also want to migrate from YOURLS to Twitter to WP to Twitter here is the way I did it.

    Entering the code Joe Dolson suggested won’t work perfectly, because afterwards you will have two shortlink entries in the head section, because WP does enter the post-id as shortlink like So we have to use a filter to change that link into “our” YOURLS shortlink.

    So here is the trick:

    First of all install and enable WP to Twitter and deactivate and delete YOURLS to Twitter.

    Go to your phpMyAdmin installation, make a backup of the database first(!) and change the existing variable name from YOURLS to Twitter that stores the shortlink into the new one from WP to Twitter by entering the following SQL-Code. Change the wp prefix of wp_postmeta into your own prefix if necessary.

    UPDATE 'wp_postmeta' SET 'meta_key' = '_wp_jd_yourls' WHERE 'meta_key' = 'yourls_shorturl'

    Now enter the following code in the functions.php of your WordPress theme.

    add_filter('pre_get_shortlink', 'gb_my_custom_shortlink', 10, 4);
    function gb_my_custom_shortlink($false, $post_id, $context, $allow_slugs) {
    	if ( (is_single() || is_page()) && !is_home() ) {
    	global $post;
    	$short_link = get_post_meta($post->ID, '_wp_jd_yourls', true);
    	if('' == $short_link) return false;
    	return $short_link;

    This code will look if the post has a shortlink stored and replace the WP default shortlink with the correct YOURLS created link.

    Plugin Author Joe Dolson


    Thanks for posting that detailed migration guide.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘From YOURLS to WP to Twitter’ is closed to new replies.