cancel
Showing results for 
Search instead for 
Did you mean: 

Seo browser title - Magento 2

Seo browser title - Magento 2

My question is. Is there a way to create a ‘simple’ module that easily echo’s the {{product_name}} and {{store_name}} of the category- and product page.. so i can use hem inside the ‘default site description’. We run version 2.1.9..

 

So in practice we want to get:

Get your new {{product_name}} from {{store_name}}, always the best prices at {{store_name}}.


But only for the Category page and Product Detail page.

Cause now if you change it with the 'standard' Magento prefix and suffix solution, the problem is also that the CMS and homepage change.

4 REPLIES 4

Re: Seo browser title - Magento 2

This is still an issue, can someone please help me

At this point i use this module from Codealist but it's just for the homepage and the problem is that the CMS pages also get a Prefix and Suffix.. if i can make a small change to this module so the CMS page's also take the default Title.. that would be great, but i don't know how..

Module:
https://www.codealist.com/magento-2-x-set-default-page-title-for-homepage/

Re: Seo browser title - Magento 2

Hello Badmintonplanet

 

Call custom phtml file below title by xml, follow below directory to open xml file and put below code.

Product Page: 

 

 

app/desigin/frontend/your_theme/module_theme/Magento_Catalog/layout/catalog_product_view.xml 

    <referenceBlock name="page.main.title">
        <block class="Magento\Catalog\Block\Product\View\Description" name="subtitle" template="product/view/subtitle.phtml" />
    </referenceBlock>

 

get subtitle attribute in subtitle.phtml.

 

 

$product = $block->getProduct();
<h1 class="page-title">
<?php echo $product->getName(); ?> and  <?php $block->getCurrentStoreName() ?><h1>

Same for category page, you need to override category xml.

 

app/desigin/frontend/your_theme/module_theme/Magento_Catalog/layout/catalog_category_view.xml

hope it will help you, if works then mark as solution.

Re: Seo browser title - Magento 2

 

Thanks @prakash786,

I've tried your solution but i don't think it's working as i want (to bad).
Did you understood what i ment by page title?

I ment the title you see when you make for instance a bookmark or the text that's getting echo'ed when you search the page on Google (see image below).Schermafbeelding-2018-08-14-om-10.47.51.jpg

Re: Seo browser title - Magento 2

Hello,

To achieve this in Magento 2.1.9, you can create a custom module to echo the `{{product_name}}` and `{{store_name}}` variables specifically for the category and product detail pages. Here's a general outline of how you can implement this:

1. **Create a Custom Module**: Start by creating a custom module in your Magento installation.

2. **Define Block Classes**: Within your custom module, define block classes that retrieve the `{{product_name}}` and `{{store_name}}` variables for the category and product detail pages.

3. **Template Modifications**: Modify the templates for the category and product detail pages to include your custom block classes and echo the desired variables (`{{product_name}}` and `{{store_name}}`).

4. **Restrict Scope**: Ensure that your modifications only apply to the category and product detail pages, excluding the CMS pages and homepage.

Here's a basic example of how you might structure your module:

```plaintext
app/
└── code/
└── Vendor/
└── Module/
├── Block/
│ ├── Category.php
│ └── Product.php
├── etc/
│ └── module.xml
└── view/
└── frontend/
├── layout/
│ ├── catalog_category_view.xml
│ └── catalog_product_view.xml
└── templates/
├── category_description.phtml
└── product_description.phtml
```

In your `Category.php` and `Product.php` block classes, you can retrieve the necessary variables (`{{product_name}}` and `{{store_name}}`). Then, in your `category_description.phtml` and `product_description.phtml` templates, you can echo these variables within the "default site description" as needed.

Ensure that your layout XML files (`catalog_category_view.xml` and `catalog_product_view.xml`) only apply these modifications to the category and product detail pages.

By following this approach, you can achieve the desired functionality without affecting the CMS pages and homepage.

If you need further assistance with specific code implementations or have any questions, feel free to ask!

Best regards,
deer