Subscription Options is a very useful wordpress plugin that enables you to share your blog content over email, RSS feed, twitter, facebook etc. It provides excellent flexibility in the form of choosing the right kind of icon and associate the required URL with the icon. See a snapshot below.
Rather than copy-pasting standalone snippets of code for each service eg twitter, it is extremely easy to rather let this plugin do the job for you. You can than just add it as a widget in your sidebar. An additional benefit is that it is very simple to enhance some code in the plugin php file and use it on your blog.
As an example, lets see how to add an [Add To Delicious] button for this plugin and have it available with rest of the icons.
All you need to do the following --
Look for the following code in your plugin file named suboptions.php( located in wp-content/plugins/subscription-options folder )
if ( $facebook_url ) echo '<a target="_blank" title="Subscribe via Facebook" alt="Subscribe via Facebook" href="'.$facebook_url.'"><img style="border: 0px none; width: '.$size.'px; height: '.$size.'px; " src="'.get_bloginfo('wpurl').'/'.PLUGINDIR.'/subscription-options/images/facebook_icon_'.$facebook_col.'.png"/> </a>';
This is the code which displays the facebook icon and associates it with a URL. We will add our new code just below this one. Notice the echo command above
- Lets say your blog’s URL is http://www.yourblog.com.
- To display the delicious icon, you would need a delicious logo image file. Lets call that file delicious_icon.png.
- This file needs to be uploaded to your site.
- For our case, lets assume it is available as images/delicious_icon.png on your blog.
- Note -- To keep things simple, choose an image with exactly the same dimensions as other icons of the plugin. This will help us to avoid any formatting tags for the image and use it as is. For example if the icon image for facebook as available in the plugin is 50px*50px -- use the same dimension image here.
- Lets assume that the URL that you want to bookmark is the home page of your blog itself -- http://www.yourblog.com.
- To keep the things simple, we will use the URL string of your home page rather than using any wordpress functions to extract the home page URL.
We are almost set now. We will just take a variable in which the homepage URL is stored. We will than invoke our own echo function that will display the icon and also link it to the desired URL. To set the perspective, If we want to say bookmark a URL XYZ to delicious, the desired URL should be “http://www.delicious.com?url=XYZ”. In our case, we need to replace XYZ by our blog’s homepage URL
Enough of description, lets look at the code snippet
$del_url = "http://www.yourblog.com"; echo '<a target="_blank" title="Add To Delicious" alt="Add To Delicious" href="http://www.delicious.com?url=' . urlencode($del_url) . '" ><img border="0" alt="Add To Delicious" src="http://www.yourblog.com/images/delicious_icon.png" /></a>';
Isnt this simple? All we are doing is putting the URL to be bookmarked in a variable and concatenating it with the final URL( after doing the required URL encoding ). The final output will show an additional icon adjacent to the existing plugin icons with the desired link action. Notice the last icon in the snapshot below.
Using this method, you can add/remove newer icons and their associated URLs in this plugin. If you are and advanced user, you might also like to use some additional wordpress APIs to build the URL dynamicaly rather than using a hardcoded string as above( to be covered later 🙂 ).
Let us know if you found this useful by sharing the thoughts in the comments section.