MuchDev Posted August 28, 2014 Share Posted August 28, 2014 Hey guys, I am strugling to get a decent spread of social share buttons on my page that doesn't totally bog everything down. I had addthis which ended up adding 2sec to page load (even when loaded asynchronously) and sharethis(which just would totally break constantly), and then I decided to just write links in php without all of their api overhead. What I was wondering is does anyone have a function that they have written already that has facebook,twitter,g+,and pinterest so I dont have to spend yet another day fussing with ugly social media documentation? http://www.sitepoint.com/social-media-button-links/ This page has a pretty nice walkthrough I was thinking I would adapt. There has to be some brilliant pw dev out there that has some slick social share button module. **Just found oEmbed. I read about that before but didn't understand what it actually does, is this something I should figure out? Link to comment Share on other sites More sharing options...
MuchDev Posted August 29, 2014 Author Share Posted August 29, 2014 Well here I go, I've got something now. Just a little social bar function ill post it once it's done. You will need to track down some extra documentation on meta tags if you dont already know but I should have a little inc file done in a bit:). One thing I am interested in is in how I should go about making the url friendly for the facebook sharer php link and such. Is it ok to use / in urls or should I try and do some extra work to substitute the characters? Link to comment Share on other sites More sharing options...
MuchDev Posted August 29, 2014 Author Share Posted August 29, 2014 Well the formatting got a little weird in the code box as they are really long links but just throw em in a text editor and you should be right as rain. I managed to find some sample code that allows you to use the pinterest image chooser as is an important thing for this project. Now just to get it out of the document into my extra js. function renderSocial(){ $soc = ''; $page = wire('page'); $thisUrl = $page->httpUrl; $path = wire('config')->urls->templates.'img/'; $lnkDesc = $page-meta_description; $friendlyUrl = urlencode($thisUrl); $friendlyDesc = ereg_replace("[-]+", "-", ereg_replace("[^a-z0-9-]", "",strtolower( str_replace(" ", "-", $lnkDesc) ) ) ); $soc .= '<div class="socialHolder">'; $soc .= ' <ul class="share-buttons">'; $soc .= ' <li><a class="socialBtn" href="https://www.facebook.com/sharer/sharer.php?u='.$friendlyUrl.'&t='.$linkTitle.'" target="_blank"><img src="'.$path.'Facebook.png"></a></li>'; $soc .= ' <li><a class="socialBtn" href="https://twitter.com/intent/tweet?source='.$friendlyUrl.'&text='.$thisUrl.'Your Title Header:'.$page->title.' '.$friendlyDesc.'" target="_blank" title="Tweet"><img src="'.$path.'Twitter.png"></a></li>'; $soc .= ' <li><a class="socialBtn" href="https://plus.google.com/share?url='.$friendlyUrl.'" target="_blank" title="Share on Google+"><img src="'.$path.'Google+.png"></a></li>'; $soc .= ' <li><a class="socialBtn" href="javascript:void((function()%7Bvar%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)%7D)());"><img src="'.$path.'Pinterest.png"></a>'; $soc .= ' </ul>'; $soc .= '</div>'; echo $soc; } 2 Link to comment Share on other sites More sharing options...
Ole Posted September 4, 2014 Share Posted September 4, 2014 I've made something like this for me as well.Another interesting thing is sharing with WhatsApp. If you don't want to push it to the wide audience, but to a special friend or group...Unfortunately it just works on iPhones.I haven't try it yet, but want to use it in my next project. The HTML Part: <a href="WhatsApp://send?text=Text durch native Deeplink!" class="WhatsAppLink" style="display:none;" >Send</a> The JS: (navigator.userAgent.match(/(iPhone)/g)) ? $(".whatsappLink").fadeIn() : null ; 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now