0

The title of my website https://agoshop.at is Agoshop Österreich and a meta title of a category is Algenentferner online kaufen

Therefore The html meta information of my site https://agoshop.at/algenentferner/ is:

<meta name="title" content="Agoshop Österreich |  Algenentferner online kaufen"/>

For SEO it is better to change the order of title with meta title. The result correct title should be:

<meta name="title" content="Algenentferner online kaufen |  Agoshop Österreich"/>

Hope someone can help me there how I can solve this. kindly regards

1 Answer 1

0

This needs to be achieve before accessing your page

You can do something like that in your block for example there you can change the title and the meta information such as robot.

/**
 * Add metadata to page header
 *
 * @return $this
 */
protected function _prepareLayout()
{
    if ($query = $this->getQuery()) {
        $title = __('Search results for "%1":', $this->escapeHtml($query));
        $this->pageConfig->getTitle()->set($title);

        /** @var \Magento\Theme\Block\Html\Title $headingBlock */
        if ($headingBlock = $this->getLayout()->getBlock('page.main.title')) {
            $headingBlock->setPageTitle($title);
        }
    }

    $this->pageConfig->setRobots('NOINDEX,NOFOLLOW');

    return parent::_prepareLayout();
}

Threw the page config you will be able to use method like setMetaTitle

3
  • Thanks for your answer. Where (in which file) must I insert the function? What do you mean with "Threw the page config you will be able to use method like setMetaTitle"? Hope you can help me again and can explain it (maybe with some pictures). My english ist not the best. kindly regards
    – haiflosse
    Commented Apr 8, 2022 at 11:51
  • You can use $this->pageConfig->setMetaTitle("your meta title").To know in wich file you need to insert this you need to look for the template (phtml) . I guess from your question it's probably the category listing product page. From this you need to find the xml layout file where the template is called. In that xml there will be a block class. It's in that block class that you need to add the method. It should look like this : <block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml"> Then simply override the block class
    – Claims
    Commented Apr 8, 2022 at 12:14
  • Thanks again for your answer. I don't know exactly what you mean. I can find a template.phtml file in the folder: vendor/magento/module-theme/view/frontend/templates. But I cannot find in the same folder a product page and a xml layout file. Please let me know how I can find the correct files. Kindly regards again
    – haiflosse
    Commented Apr 12, 2022 at 7:56

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.