Lewis' Blog Tales from the trenches of information technology

26Jul/121

Removing social networking links from WPtouch (free version)

Download PDF

I hate social networking.

If you're a regular reader of this site, you probably know that by now.

While I truly love the WPtouch mobile plugin for WordPress, and while I really should upgrade to the Pro version (note to self: let's do this before the end of the year), I absolutely hate those links to Tw-tter and F-c-book at the bottom of each article. I do like the email and bookmark links, though, as well as the navigation buttons.

A little poking around got me what I needed to find. The hack is fairly simple.

You want to dig down to wp-content/plugins/wptouch/themes/core/core-functions.php. Make a backup copy of the existing file, and then open the original in your favorite editor. Search down the file until you find:

function wptouch_twitter_link() {
    echo '<li><a href="javascript:(function(){var%20f=false,t=true,a=f,b=f,u=\'\',w=window,d=document,g=w.open(),p,linkArr=d.getElementsByTagName(\'link\');for(var%20i=0;i%3ClinkArr.length&&!a;i++){var%20l=linkArr[i];for(var%20x=0;x%3Cl.attributes.length;x++){if(l.attributes[x].nodeName.toLowerCase()==\'rel\'){p=l.attributes[x].nodeValue.split(\'%20\');for(y=0;y%3Cp.length;y++){if(p[y]==\'short_url\'||p[y]==\'shorturl\'||p[y]==\'shortlink\'){a=t;}}}if(l.attributes[x].nodeName.toLowerCase()==\'rev\'&&l.attributes[x].nodeValue==\'canonical\'){a=t;}if(a){u=l.href;}}}if(a){go(u);}else{var%20h=d.getElementsByTagName(\'head\')[0]||d.documentElement,s=d.createElement(\'script\');s.src=\'http://api.bit.ly/shorten?callback=bxtShCb&longUrl=\'+encodeURIComponent(window.location.href)+\'&version=2.0.1&login=amoebe&apiKey=R_60a24cf53d0d1913c5708ea73fa69684\';s.charSet=\'utf-8\';h.appendChild(s);}bxtShCb=function(data){var%20rs,r;for(r%20in%20data.results){rs=data.results[r];break;}go(rs[\'shortUrl\']);};function%20go(u){return%20g.document.location.href=(\'http://mobile.twitter.com/home/?status=\'+encodeURIComponent(document.title+\'%20\'+u));}})();" id="otweet"></a></li>';
}

and remove the second line (highlighted), ending up with:

function wptouch_twitter_link() {
}

and then do the same with the following:

function wptouch_facebook_link() {
    echo "<li><a href=\"javascript:var%20d=document,f='http://www.facebook.com/share',l=d.location,e=encodeURIComponent,p='.php?src=bm&v=4&i=1297484757&u='+e(l.href)+'&t='+e(d.title);1;try{if%20(!/^(.*\.)?facebook\.[^.]*$/.test(l.host))throw(0);share_internal_bookmarklet(p)}catch(z)%20{a=function()%20{if%20(!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=1,width=626,height=436'))l.href=f+p};if%20(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else{a()}}void(0)\" id=\"facebook\"></a></li>";
}

removing the second line again, leaving:

function wptouch_facebook_link() {
}

Save the modified file.

This hack changes:

Default WPTouch ShareBar

ShareBar, showing social networking links

into this:

WPTouch ShareBar without social networking links

ShareBar, showing social networking links removed.

Note that with each update to the plugin you will need to re-do this hack. A nicer way would be for BraveNewCode to support a preference (and they do in the Pro version, which I would highly recommend).

This post should in no way be taken as an endorsement to use the free version instead of the Pro version, but rather as an example of what can be achieved by poking around in the code for yourself, and tailoring things to fit your particular needs.

N.B.: Thanks to Lisa for the hint about the incorrect file pointer in the original version of this article!