0

Client provided an audit report of his website and on that report, he mentioned some pages have duplicate title and content as shown below picture, how to fix those URLS any idea? enter image description here

enter image description here

1 Answer 1

1

Contact and Contact/ are the same url these arent an issue.

So your client need to fix his file first.

That being said it depends on what the pages are.

If they are product or category you can update them by providing the seo title i think.

If not then make an obsever that will edit the title of the cms page.

Here is a piece of observer i already used for that purpose

/**
 * This class will handle pages outside of catalog
 * @param Observer $observer
 * @return void
 * @throws \Magento\Framework\Exception\NoSuchEntityException
 */
public function execute(Observer $observer)
{
    //Works on cms page and category page to change h1 title
    $currentUrl = $this->urlInterface->getCurrentUrl();
    $currentUrlCleaned = str_replace('%','%%',$currentUrl);
    $this->loggerTitle->logInfo("For all pages : check url %s",[$currentUrlCleaned]);

    /** @var PageConfig $pageConfig */
    $layout = $observer->getData('layout');
    $blockTitle = $layout->getBlock('page.main.title');


    $h1Title = null;
   if($this->layerResolver->get()->getData() != null){
       //Category
       //Turns out cms pages seems to belong to the default category, so we need to prevent the case
       $isCmsPage = ($this->layerResolver->get()->getCurrentCategory()->getId() == null ||
           $this->layerResolver->get()->getCurrentCategory()->getId() == 2);
       if(!$isCmsPage){
           $h1Title = $this->layerResolver->get()->getCurrentCategory()->getData('page_h1_title');
       }
   }else{
       //"CMS PAGE"
       if($this->page != null){
           $h1Title = $this->page->getData('page_h1_title');
       }
       //Unknown CMS page, handled by custom RAW URL in  seo_meta table
       if($h1Title == null){
           $h1Title = $this->seoHelper->getH1Title();
       }
   }
    if($blockTitle !== false && $h1Title != null){
        $blockTitle->setTitle($h1Title);
        $blockTitle->setPageTitle($h1Title);
        $this->loggerTitle->logSuccess('Apply title  %s',[$h1Title]);
    }else{
        $this->loggerTitle->logError("Can't update the title : title block is missing");
    }
}

EDIT : Event

    <event name="layout_generate_blocks_after">
        <observer name="vendor_seo_custom_observer" instance="Vendor\Seo\Observer\ChangeTitleObserver"/>
    </event>

5
  • whats the event name? Commented Nov 6, 2023 at 14:18
  • @AfzelArshad See edits.
    – Claims
    Commented Nov 6, 2023 at 16:40
  • $this->seoHelper->getH1Title(), what class is this, i couldn't find it Commented Nov 7, 2023 at 7:42
  • that's a custom method i used to retrieve data in a custom seo table matching my client requirements. You don't have to use it you can just set there any title you want
    – Claims
    Commented Nov 7, 2023 at 12:14
  • what about duplicate content of cms pages? Commented Nov 7, 2023 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.