vaersaagod / seomate

SEO, mate! It's important. That's why SEOMate provides the tools you need to craft all the meta tags, sitemaps and JSON-LD microdata you need - in one highly configurable, open and friendly package - with a super-light footprint.
MIT License
36 stars 8 forks source link

Set sitename from global set field value #21

Closed piotrpog closed 5 months ago

piotrpog commented 5 years ago

It seems that right now we cannot set sitename (value that is appended to title) from global set field value.

I tried this and it didn't worked:

'siteName' => ['globalSeo.globalseofields:settings.description'],

While this generated array to string conversion error:

'siteName' => [
    'default' => ['globalSeo.globalseofields:settings.description'],
],

Setting sitename from string value works fine:

'siteName' => 'x',
mmikkel commented 5 years ago

It's currently not possible to use field values for the siteName setting. As stated in the docs, the siteName setting can either be a string, or an array with site handles as keys and strings as values.

piotrpog commented 5 years ago

@mmikkel Sometimes site name is internal value, meant to be seen only by admins. I would like to be able to overwrite it, and allow admin to modify this overwritten value - that's why i proposed it.

mmikkel commented 5 years ago

@piotrpog I'm not sure if I understand the use case, but needing the site name to be dynamic sounds like an edge case to me. If you need the site name to be dynamic (beyond having a different name per site), you can either use a template override:

{% set globalSettings = globalSeo.globalseofields.type('settings').one() %}

{% set seomate = {
    config: {
        siteName: (globalSettings ? globalSettings.description)|default(siteName)
    }
} %}

...or if you really wanted to do it in the config/seomate.php file, that's possible too:


<?php

$globalSettings = Craft::$app->getGlobals()->getSetByHandle('globalSeo')->globalseofields->type('settings')->one();

return [
    '*' => [
        'siteName' => ($globalSettings ? $globalSettings->description : null) ?: Craft::$app->getSites()->getCurrentSite()->name,
        ...
    ],
];
piotrpog commented 5 years ago

I think PHP snippet will do a trick. Thanks. But I disagree that it is edge case. Often I name my sites "english version", "german version" etc. These names are good for content creators so they know what to click in language switcher when they edit entries. But I cannot have these names appended to title value in metatags. And yet I want to give admin ability to change specific string that is appended to title tag through a control panel.

mmikkel commented 5 years ago

Yeah... I meant "edge case" as in, I don't think most sites need to give content editors the ability to change site names in the CP. But, I've labelled this as a feature request and we might add support for custom fields for the siteName setting at some point in the future.

nilsenpaul commented 2 years ago

First of all: we've just started using your plugin, love the 'no UI for config' approach!

In our use case, we also need the siteName setting to be configurable by the content editors, because they sometimes want side-wide 'Month X side-wide DISCOUNT SPREE' in every page title.

We've solved this with a SEO global and some PHP in seomate.php, but wouldn't it be relatively easy to parse the siteName config value for Twig (as you do with other config settings)? If Twig could be used, we could just set the value to '{{ seoGlobal.siteTitle ?? craft.app.sites.currentSite.name }}' and be done with it, no PHP would be needed.

Again, it's solved and it works right now, but I think it would be an improvement.

aelvan commented 2 years ago

Yes, that's probably a good solution. I'll reopen and circle back to it.

mmikkel commented 5 months ago

...support for rendering Twig for the siteName config setting was added way back in SEOMate v. 1.1.12, but we neglected to close this issue 🙈