Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entry title not being used for SEO page title #479

Closed
andrewhawkes opened this issue May 2, 2024 · 7 comments
Closed

Entry title not being used for SEO page title #479

andrewhawkes opened this issue May 2, 2024 · 7 comments
Assignees

Comments

@andrewhawkes
Copy link

Description

In the settings I have the default settings to use the entry title and site name:

image

When creating a new entry, the title does not get used from the entry:

image

I noticed this started happening after upgrading from v5.0.0-rc1

Steps to reproduce

  1. Add a new entry which has the SEO field
  2. The title of the entry is not used in the SEO title

Additional info

  • Craft version:
  • SEO version: v5.0.0-rc2
  • PHP version: 8.2.15
  • Database driver & version: MySQL 8.0.33
  • Other Plugins:
@scoch5
Copy link

scoch5 commented May 2, 2024

Hi,
i have the same problem!

@pascalminator
Copy link

Can confirm I have the same exact problem on two different sites running Craft 5.

@jasonlav
Copy link

jasonlav commented May 8, 2024

Changing it to {{ title }} to match {{ siteName }} does not appear to resolve the issue. Nor does {{ entry.title }}.

@jasonlav
Copy link

jasonlav commented May 8, 2024

After further investigation, it appears there are multiple issues contributing to the problem.

  1. The _getVariables method in SeoData.php only adds custom fields to the $variables array that compiles the title template. Adding the following snippet appends all native attributes of the entry to the $variables array.
foreach ($this->_element->attributes() as $attribute) {
  $variables[$attribute] = $this->_element->{$attribute};
}

However, it probably isn't the best practice to do this since there could easily be naming conflicts. Rather, it would be better to add element as a new attribute of the $variables array. The title token would then be {{ element.title }}.

if (!array_key_exists('element', $variables) && $this->_element)
  $variables['element'] = $this->_element;
  1. The _renderObjectTemplate method in SeoData.php doesn't appear to be accepting the variables passed in. I ended up changing:
$str = Craft::$app->view->renderObjectTemplate($template, $object);

To:

$str = Craft::$app->view->renderObjectTemplate($template, [], $object);

In my testing these changes work. However, I'm not familiar enough with Craft's Element model and renderObjectTemplate to recommend this solution, otherwise I would submit a pull request. Perhaps the maintainer of the plugin can weigh in.

Tam added a commit that referenced this issue May 29, 2024
Tam added a commit that referenced this issue May 29, 2024
@pascalminator
Copy link

This problem is fixed now with v5.0.0-rc3. Thank you @Tam

@ryanfoote
Copy link

I think I have this same issue with v4.2.2 of the plugin. Has anyone else running the same version run into this error?

@andrewhawkes
Copy link
Author

Not sure if this is part of the same issue - but if you have a title that contains a | or - only the text after those characters is used for the {title}

I.e. if the title of an entry is ABC | 123 the meta title will be 123

@Tam Tam closed this as completed Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants
@Tam @ryanfoote @andrewhawkes @scoch5 @jasonlav @pascalminator and others