2

I'm having this issue with joomla 2.5 and the Meta robots tag.

Basically joomla has this black hole in it that doesn't matter what the URL is as long as you have a article id that is valid it will generate a page.

example:

http://www.clet.edu.au/dasfjahsd/sajfhas/61-afssfas

61 is a valid id so it will display a page however it is a wrong rendering of the page.

this will be the correct rendering for that article

http://www.clet.edu.au/online-study/whs-courses/diploma-of-work-health-and-safety

What i've came up with is, our website doesn't have any urls with numbers on it, so pretty much any url that has a number on it it's wrong... so i've done this code:

$(document).ready(function(){
var pathname = $(location).attr('href');
var NO_NUMB = new RegExp("[0-9]");
if (NO_NUMB.test(pathname)) {
$('meta[name=robots]').attr("content", "noindex, nofollow");
} 
}); 

What it does, it checks for numbers on the url and changes the meta robots to noindex nofollow. That works in part, it changes the meta robots but only does it on the browser DOM and not straight on the source file.

So when you go on your browser and click inspect element you can se the noindex nofollow tag but when you click view source, you will see index follow...

According to google support, google looks at the page source not the DOM on the browser... so it will never see the noindex nofollow tag...

I'm wondering is there a way to do that on PHP so it changes the meta keyword on the source code not on the browser DOM?

cheers, dan

dan k
  • 139
  • 2
  • 11

1 Answers1

2

Try this ,

Instead of changing the meta data from Javascript try it from php. Joomla have a document class for this purpose.

$document = JFactory::getDocument();
$document->setMetaData('keywords', "keyword1,keyword2, etc.");
$document->setMetaData('robots', "index,follow");
$document->setMetaData('author', "Jobin Jose");
$document->setMetaData('title', "Your meta title");
$document->setDescription( "Your meta description" );
$document->setTitle("This is my page title");

For more details read article How to set meta info of Joomla page

Hope its helps..

Jobin
  • 8,238
  • 1
  • 33
  • 52
  • i need to find a way to identify the URL and look for numbers, than change the code... also from some reason my joomla doesn't have the code above... all i have is `if (isset($data['metaTags'])) { foreach ($data['metaTags'] as $type1 => $data1) { $booldog = $type1 == 'http-equiv' ? true : false; foreach ($data1 as $name2 => $data2) { $this->setMetaData($name2, $data2, $booldog); } } }` – dan k Feb 25 '14 at 04:30
  • ok, The above code is used for adding custom meta tags that you can use anywhere if u want. first you have to get the current URL then check that have numbers or (your special condition) after that you can set those with above tags. does it make sense.? – Jobin Feb 25 '14 at 05:04
  • as soon as you load this on the index.php the entire site crashes $document->setMetaData('robots', "index,follow"); – dan k Feb 25 '14 at 05:57
  • if u are working on specific component add the code into that particular view or in index.php u placed this then it should apply for all the pages so put the code into particular component like if(JRequest::getVar('option') == 'com_content'){ ..codes} only for article section. – Jobin Feb 25 '14 at 06:16
  • yes thats what i tried and i get a blank page... :S – dan k Feb 25 '14 at 21:40