Back to SEO Extension Support

markfasel5594
markfasel5594

Hi, Is there way to set the page title on a page by page basis rather than it taking the default title i give the page? IE custom SEO title?

abbasadel
abbasadel

I'd love to know the answer to that as well.

axomat
axomat

I think you need to explain a bit more...

You can already set the page title uniquely to each page in core October CMS. If you mean that you do not want to prepend or append the seo site title then just dont set it.

Or did you want something else?

abbasadel
abbasadel

Thanks axomat for your reply.

I have a product.htm page where the default title is "Product". I want to be able to set the page title to the product name instead of having the same "Product" title for all pages.

title = "Product"
url = "/products/:slug"
layout = "default"

I'm using a Product component that I created myself and inside the onRun() function I try to set the page title to the product name but nothing changes.

<?php
function onRun(){
  $this->page->title = $product->name;
}
?>

Do you think it is possible to have this with your plugin?

Thanks, Abbas

Last updated

axomat
axomat

Its not my plugin but I would like to help you if I can.

The plugin does not support what you want out of the box. However you can override its partial and change the page title to refer to a variable, say $this->page['currentProduct'], that you have set in your own product component. You could append the page_title with the product name for example. I hope that is what you were trying to do.

abbasadel
abbasadel

Good idea. I will try that.

Thank you so much. Abbas

Johnny D.
Johnny D.

The approach mentioned by Abbas will work but first you need to make a little change to seo extension component classes. For example, in \anandpatel\seoextension\components\CmsPage.php just change the method from onRun() to onRender().

Then the following code will work fine:

title = "Product"
url = "/products/:slug"
layout = "default"
==
function onEnd(){
  $this->page->title = $product->name;
}
==
?>

Last updated

daniel7901
daniel7901

Is there any additional information about this issue? I am having a similar problem with Rainlab blog categories not setting the SEO and page titles correctly. While the above fixes may work, modifying the core plugin files is not a good solution.

Last updated

Colbydude
Colbydude

A little late to the party, but you can override for more dynamic SEO by doing this:

function onEnd()
{
    // Overwrite for better SEO.
    $this->layout->components['SeoCmsPage']->seo_title = 'My dynamic title.';
    $this->layout->components['SeoCmsPage']->seo_description = 'My dynamic description.'
    $this->layout->components['SeoCmsPage']->canonical_url = 'http://mywebsite.com/canonical';
}
// ...etc

This way you can just throw the SeoCmsPage component in your layout, then use the plugin as intended, or override if you have a dynamic page (say for forum threads, or events).

My personal example:

function onEnd()
{
    // Overwrite for better SEO.
    $this->layout->components['SeoCmsPage']->seo_title = $this->page->components['lcEvent']->event->title . ' | My Website';
    $this->layout->components['SeoCmsPage']->seo_description = $this->page->components['lcEvent']->event->excerpt ? $this->page->components['lcEvent']->event->excerpt : $this->layout->components['SeoCmsPage']->seo_description;
    $this->layout->components['SeoCmsPage']->canonical_url = 'https://mywebsite.com/event/' . $this->page->components['lcEvent']->event->slug;
}

Last updated

Cpt.Meatball
Cpt.Meatball

Colbydude said:

A little late to the party, but you can override for more dynamic SEO by doing this:

function onEnd()
{
   // Overwrite for better SEO.
   $this->layout->components['SeoCmsPage']->seo_title = 'My dynamic title.';
   $this->layout->components['SeoCmsPage']->seo_description = 'My dynamic description.'
   $this->layout->components['SeoCmsPage']->canonical_url = 'http://mywebsite.com/canonical';
}
// ...etc

This way you can just throw the SeoCmsPage component in your layout, then use the plugin as intended, or override if you have a dynamic page (say for forum threads, or events).

My personal example:

function onEnd()
{
   // Overwrite for better SEO.
   $this->layout->components['SeoCmsPage']->seo_title = $this->page->components['lcEvent']->event->title . ' | My Website';
   $this->layout->components['SeoCmsPage']->seo_description = $this->page->components['lcEvent']->event->excerpt ? $this->page->components['lcEvent']->event->excerpt : $this->layout->components['SeoCmsPage']->seo_description;
   $this->layout->components['SeoCmsPage']->canonical_url = 'https://mywebsite.com/event/' . $this->page->components['lcEvent']->event->slug;
}

Hmm, for some reason I can't get that to work. It keeps putting the standard CMS page title in the header

jamesfawcett
jamesfawcett

Sorry for digging up an old post but this comes up top post on Google, I solved this with the following:

    {% if this.page.settings.meta_title is not null %}
    <title>{{ this.page.settings.meta_title }}</title> 
    {% elseif this.page.components['blogPost'].post.attributes.seo_title is not null %}
    <title>{{ this.page.components['blogPost'].post.attributes.seo_title }}</title> 
    {% else %}
    <title>{{ this.page.title }}</title>
    {% endif %}

Last updated

1-11 of 11