How to create links to Social Media web sites from dynamic PHP pages

Link sharing on social media websites (which is a catch-all term for social networking and social bookmarking sites) is a great way to dramatically improve your traffic and search engine ranking. There is a lot of free tools for sharing your content on social networking and social bookmarking sites but they give you little or no control over the link anchor text and description of your content. The result is that the links created with these tools will have very limited SEO value - which means they are not likely to improve your site's Google rank and search engine ranks in general. Instead they provide huge SEO value to the website offering you this kind of 'free' solution - not exactly what you wanted... This article is the result of our effort to create an easy to use social media link codes to add social networking and social bookmarking links to PHP web pages with special attention given to dynamic, typically database driven content. Of course the whole idea can be used to create analogous code for ASP and ASP .NET web sites. The rest of the article is a step by step guide to adding changes to your PHP code to support links to social media websites. For a working example please see PC Tools AntiVirus on our website at the bottom of the page.

Social media link sharing icons

You need to get good looking icons for social media so ... go to Google, select Image search and enter 'social media icons' and you will find millions of them. Make sure you use free ones or pay for the ones which are for a fee. Place the following icons in the 'images' folder on your site. The icons MUST be named exactly as below:

  • BlinkList.png
  • Delicious.png
  • Digg.png
  • Diigo.png
  • Facebook.png
  • LinkedIn.png
  • Reddit.png
  • StumbleUpon.png
  • Technorati.png
  • Twitter.png
  • Newsvine.png
  • Mixx.png
  • DZone.png

or you have to change the code which comes in the next step.

Support functions for social networking and social media link sharing

First you need to select which of your pages will have the links to social media and find the corresponding PHP file. Create a space for a new code section in your PHP file and add the following code. You will have to modify the code as explained in comments for each function. This is the most important part of the work because it determines the content which is going to be passed to social media sites.

<?php 
    
/*
     * The functions below need to be modified by you to return database driven results based 
     * on your actual data. 
     */ 

    
function smcPermalink()
    {
        
/* 
         * Modify this function to build the complete, SEO optimized url for your page. 
         * This is the url you want to share on social media. Typically this is the url 
         * of the current page.
         */
        
$permalink "http://www.softwaremastercenter.com/pc-tools-antivirus_11719-6_software.html";
        return 
$permalink;
    }

    function 
smcShortPermalink()
    {
        
/* 
         * Modify this function to build the complete short url for your page, if one exists, useful 
         * for Tweeter. If one does not exist just delegate to smcPermalink(). 
         */
        
$shortPermalink "http://www.softwaremastercenter.com/detail.php?id=11719-6";
        return 
$shortPermalink;
    }

    function 
smcTitle()
    {
        
/* 
         * Modify this function to provide the anchor text for the link to your web page. Make
         * sure this is SEO optimized.
         */
        
$title "PC Tools AntiVirus";
        return 
$title;
    }

    function 
smcExcerpt()
    {
        
/* 
         * Modify this function to provide the description for your web page. Make
         * sure this is SEO optimized. 
         */
        
$description "PC Tools AntiVirus provides world-leading protection against viruses, "
                   
."worms and Trojans with rapid updates and OnGuard technology.";
        return 
$description;
    }
?>

Actual social media link codes

Now that you have the support functions added to your PHP page you need to designate a place on your web page where the social media icons are going to appear. Once you have the place add the following html section:

<div style="margin-top:20px;margin-bottom:10px">
    <span>
        <span style="vertical-align:bottom;color:#E43A0D;">Share it!&nbsp;&nbsp;&nbsp;</span>
        <a rel="nofollow" target="_blank" href="http://delicious.com/post?url=<?php echo urlencode(smcPermalink()); ?>&title=<?php echo urlencode(smcTitle()); ?>&notes=<?php echo urlencode(smcExcerpt()); ?>" title="Bookmark this page at Delicious"><img style="vertical-align:middle;display:inline;border-style:none" title="Bookmark <?php echo smcTitle() ?> at Delicious" alt="Bookmark  <?php echo smcTitle() ?> at Delicious" src="images/Delicious.png" /></a>
        <a rel="nofollow" target="_blank" href="http://digg.com/submit?phase=2&url=<?php echo urlencode(smcPermalink()); ?>&title=<?php echo urlencode(smcTitle()) ?>" title="Submit this page to Digg"><img style="vertical-align:middle;display:inline;border-style:none" title="Digg <?php echo smcTitle() ?>" alt="Digg <?php echo smcTitle() ?>" src="images/Digg.png" /></a>
        <a rel="nofollow" target="_blank" href="http://twitter.com/home?status=Check out the <?php echo urlencode(smcTitle()) ?> at <?php echo urlencode(smcShortPermalink()); ?>" title="Share this page with your Twitter followers"><img style="vertical-align:middle;display:inline;border-style:none" title="Share <?php echo smcTitle() ?> with your Twitter followers" alt="Share <?php echo smcTitle() ?> with your Twitter followers" src="images/Twitter.png" /></a>
        <a rel="nofollow" target="_blank" href="http://www.stumbleupon.com/submit?url=<?php echo urlencode(smcPermalink()); ?>&title=<?php echo urlencode(smcTitle()); ?>" title="Share this page at StumbleUpon"><img style="vertical-align:middle;display:inline;border-style:none" title="Share <?php echo smcTitle() ?> at StumbleUpon" alt="Share <?php echo smcTitle() ?> at StumbleUpon" src="images/StumbleUpon.png" /></a>
        <a rel="nofollow" target="_blank" href="http://technorati.com/faves?add=<?php echo urlencode(smcPermalink()); ?>" title="Add to your Technorati favorites"><img style="vertical-align:middle;display:inline;border-style:none" title="Add <?php echo smcTitle() ?> to your Technorati favorites" alt="Add <?php echo smcTitle() ?> to your Technorati favorites" src="images/Technorati.png" /></a>
        <a rel="nofollow" target="_blank" href="http://www.facebook.com/sharer.php?u=<?php echo urlencode(smcPermalink());?>&t=<?php echo urlencode(smcTitle()); ?>" title="Share this page on Facebook"><img style="vertical-align:middle;display:inline;border-style:none" title="Share <?php echo smcTitle() ?> on Facebook" alt="Share <?php echo smcTitle() ?> on Facebook" src="images/Facebook.png" /></a>
        <a rel="nofollow" target="_blank" href="http://blinklist.com/blink?u=<?php echo urlencode(smcPermalink()); ?>&t=<?php echo urlencode(smcTitle()); ?>&d=<?php echo urlencode(smcExcerpt()); ?>" title="Share this page on Blinklist" ><img style="vertical-align:middle;display:inline;border-style:none" title="Share <?php echo smcTitle() ?> on Blinklist" alt="Share <?php echo smcTitle() ?> on Blinklist" src="images/BlinkList.png" /></a>
        <a rel="nofollow" target="_blank" href="http://www.diigo.com/post?title=<?php echo urlencode(smcTitle()); ?>&url=<?php echo urlencode(smcPermalink()); ?>" title="Share this page on Diigo"><img style="vertical-align:middle;display:inline;border-style:none" title="Share <?php echo smcTitle() ?> on Diigo" alt="Share <?php echo smcTitle() ?> on Diigo" src="images/Diigo.png" /></a>
        <a rel="nofollow" target="_blank" href="http://reddit.com/submit?url=<?php echo urlencode(smcPermalink()); ?>&title=<?php echo urlencode(smcTitle()); ?>" title="Share this page on Reddit"><img style="vertical-align:middle;display:inline;border-style:none" title="Share <?php echo smcTitle() ?> on Reddit" alt="Share <?php echo smcTitle() ?> on Reddit" src="images/Reddit.png" /></a>
        <a rel="nofollow" target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo urlencode(smcPermalink()); ?>&title=<?php echo urlencode(smcTitle()); ?>&summary=<?php echo urlencode(smcExcerpt()); ?>" title="Share this page on Linked In"><img style="vertical-align:middle;display:inline;border-style:none" title="Share <?php echo smcTitle() ?> on Linked In" alt="Share <?php echo smcTitle() ?> on Linked In" src="images/LinkedIn.png" /></a>
        <a rel="nofollow" target="_blank" href="http://www.newsvine.com/_tools/seed&save?u=<?php echo urlencode(smcPermalink()); ?>&h=<?php echo urlencode(smcTitle()); ?>" title="Seed the vine"><img style="vertical-align:middle;display:inline;border-style:none" title="Seed the vine with <?php echo smcTitle() ?>" alt="Seed the vine with <?php echo smcTitle() ?>" src="images/Newsvine.png" /></a>
        <a rel="nofollow" target="_blank" href="http://www.mixx.com/submit?page_url=<?php echo urlencode(smcPermalink()); ?>&title=<?php echo urlencode(smcTitle()); ?>" title="Share this page on Mixx"><img style="vertical-align:middle;display:inline;border-style:none" title="Share <?php echo smcTitle() ?> on Mixx" alt="Share <?php echo smcTitle() ?> on Mixx" src="images/Mixx.png" /></a>
        <a rel="nofollow" target="_blank" href="http://www.dzone.com/links/add.html?url=<?php echo urlencode(smcPermalink()); ?>&title=<?php echo urlencode(smcTitle()); ?>" title="Share this page on DZone"><img style="vertical-align:middle;display:inline;border-style:none" title="Share <?php echo smcTitle() ?> on DZone" alt="Share <?php echo smcTitle() ?> on DZone" src="images/DZone.png" /></a>
    </span>
    <br />
    <a href="http://www.softwaremastercenter.com" style="color:#E43A0D" target="_blank"><span style="font-size:small">free shareware downloads</span></a>
</div>

As you can see this code is lengthy. It takes care of url encoding of your data, alt tags, title tags and other html requirements.

Sit back and enjoy SEO benefits from links placed by your visitors on Facebook, Digg and other social networking and social bookmarking websites!

Share this article!    Bookmark How to create links to Social Media web sites from dynamic PHP pages at Delicious Digg How to create links to Social Media web sites from dynamic PHP pages Share How to create links to Social Media web sites from dynamic PHP pages with your Twitter followers Share How to create links to Social Media web sites from dynamic PHP pages at StumbleUpon Add How to create links to Social Media web sites from dynamic PHP pages to your Technorati favorites Share How to create links to Social Media web sites from dynamic PHP pages on Facebook Share How to create links to Social Media web sites from dynamic PHP pages on Blinklist Share How to create links to Social Media web sites from dynamic PHP pages on Diigo Share How to create links to Social Media web sites from dynamic PHP pages on Reddit Share How to create links to Social Media web sites from dynamic PHP pages on Linked In Seed the vine with How to create links to Social Media web sites from dynamic PHP pages Share How to create links to Social Media web sites from dynamic PHP pages on Mixx Share How to create links to Social Media web sites from dynamic PHP pages on DZone