Back

SEO: Code to Prevent Duplicate Title Tags from Different Structures

Description

Sometimes two or more structures can have structure items with the same page title.  Search engines may flag the pages as duplicate content.  

To fix this issue you will be required to change the page title of each page which may be cumbersome so you may want to set a word or more to display after the page title depending on the structure.  For example:

costarica.com/attractions/arenal-volcano - Page title generated by dotCMS Arenal Volcano

costarica.com/images/arenal-volcano - Page title generated by dotCMS Arenal Volcano

costarica.com/blog/arenal-volcano - Page title generated by dotCMS Arenal Volcano

An easy way to do this is simply changing the title field of your structure item, but when you really can not due to content specific reasons you have to resource to something else.

The code below when place in your head container will allow you to set which structures and what words to add to them so you don't have duplicate page titles for specific structures.

Code

#if($URLMapContent)
#set($stInode = $URLMapContent.structureInode)
#if(!$UtilMethods.isSet($stInode))
#set($stInode = $URLMapContent.stInode)
#end
#set($stObj = $structures.findStructure($stInode))
#set($stName =$stObj.velocityVarName)


#if($stName =="PutYourStructureNameHere")
 
#set($pageTitle = $URLMapContent.contentTitle + " PutTheWordYouWanttoAddtoPageTitleHere") 
#set($crumbTitle = $URLMapContent.contentTitle)

#elseif($stName =="PutYourStructureNameHere")
#set($pageTitle = $URLMapContent.contentTitle + "PutTheWordYouWanttoAddtoPageTitleHere") 
#set($crumbTitle = $URLMapContent.contentTitle)

#else

#set($pageTitle = $URLMapContent.contentTitle) 
#set($crumbTitle = $pageTitle) 

#end
#end