Tuesday, February 5, 2013

How-to hide joomla plugin conditional on some pages

Problem:     We need to hide joomla plugin like sharethis social buttons only on some pages, we don't need to show that plugin on simple layout article only on blog types


1. Download plugin file from folder: plugins/content/sharethis.php
2. Add a function to read the base url where the plugin is loaded on the start of the file, just after ?php line.


function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
 } else {
 return $pageURL;

3.- Now we need to create a condition for only display the plugin where the url contain string "layout=blog", see url sample:

4.- We end our piece of code adding the condition if we found a substring "layout-blog" inside the base url, see the code in green with our modiifcation on sharethis.php plugin.

$url = curPageURL();
if (strpos($url,'layout=blog')) {
/* Return whole button style code with article title and article url values. */
$url = JURI::root().ContentHelperRoute::getArticleRoute($article->id, $article->catid);
return "<DIV style='text-align:".$this->_alignment.";padding-bottom:30px;padding-top:10px'>".$this->showWidget().$this->getWidgetStyle($url,$article->title)."</DIV>";
/* that the code to return to function when the condition is tru on lyout=blog
return "<DIV id='hidden'></DIV>";

That's all folks ;-)

1 comment: