nystudio107 / craft-seomatic

SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.
https://nystudio107.com/plugins/seomatic
Other
166 stars 71 forks source link

homepage in structure #266

Closed proximo7 closed 6 years ago

proximo7 commented 6 years ago

I have a homepage in a structure inside a Craft 3 multi-site setup. SEOMatic is working beautifully on all site pages except the homepage. I can't get it to display anything from the homepage entry.

Using {{ entry.seo.metaGlobalVars.seoTitle }} returns the correct data in the template so I'm not sure why SEOMatic isn't displaying any content.

khalwat commented 6 years ago

What version of SEOmatic are you using?

What you're dumping is just what is in the field -- what if you do something like

{{ dump(seomatic.meta) }}

?

proximo7 commented 6 years ago

I'm using 3.1.28 with Craft 3.0.30.1. When I use the dump tag I get: object(nystudio107\seomatic\models\MetaGlobalVars)#476 (35) { ["language"]=> NULL ["mainEntityOfPage"]=> string(7) "WebSite" ["seoTitle"]=> string(0) "" ["siteNamePosition"]=> string(5) "after" ["seoDescription"]=> string(0) "" ["seoKeywords"]=> string(0) "" ["seoImage"]=> string(0) "" ["seoImageWidth"]=> string(0) "" ["seoImageHeight"]=> string(0) "" ["seoImageDescription"]=> string(0) "" ["canonicalUrl"]=> string(36) "{seomatic.helper.safeCanonicalUrl()}" ["robots"]=> string(3) "all" ["ogType"]=> string(7) "website" ["ogTitle"]=> string(24) "{seomatic.meta.seoTitle}" ["ogSiteNamePosition"]=> string(4) "none" ["ogDescription"]=> string(30) "{seomatic.meta.seoDescription}" ["ogImage"]=> string(0) "" ["ogImageWidth"]=> string(0) "" ["ogImageHeight"]=> string(0) "" ["ogImageDescription"]=> string(35) "{seomatic.meta.seoImageDescription}" ["twitterCard"]=> string(7) "summary" ["twitterCreator"]=> string(29) "{seomatic.site.twitterHandle}" ["twitterTitle"]=> string(24) "{seomatic.meta.seoTitle}" ["twitterSiteNamePosition"]=> string(4) "none" ["twitterDescription"]=> string(30) "{seomatic.meta.seoDescription}" ["twitterImage"]=> string(0) "" ["twitterImageWidth"]=> string(0) "" ["twitterImageHeight"]=> string(0) "" ["twitterImageDescription"]=> string(35) "{seomatic.meta.seoImageDescription}" ["_errors":"yii\base\Model":private]=> NULL ["_validators":"yii\base\Model":private]=> NULL ["_scenario":"yii\base\Model":private]=> string(7) "default" ["_events":"yii\base\Component":private]=> array(0) { } ["_eventWildcards":"yii\base\Component":private]=> array(0) { } ["_behaviors":"yii\base\Component":private]=> NULL }

khalwat commented 6 years ago

Interesting. I'll set up a test case, but it should be finding the appropriate container even if the slug is __home__ for the structure.

khalwat commented 6 years ago

Can you tell me how you designated an entry in the structure to be the homepage? I'm trying to set up a test here to replicate the issue @pioneerdesign

khalwat commented 6 years ago

So I was able to set up a test environment for this, but it's working as expected. Are you doing something unusual to handle the "homepage" of the section?

proximo7 commented 6 years ago

I have the homepage as a page within a general "pages" structure. It's an entry type with custom fields and includes the SEOMatic field (just like all other pages within this structure). Then on the index.html page I'm calling this entry directly: {% set home = craft.entries.slug('homepage') %} {% for entry in home.all() %} ...

If there is a better way I'm certainly open to it.

khalwat commented 6 years ago

Ah okay yeah that's why, SEOmatic can't automatically know that you're doing this.

You have a few choices:

1) You can set the homepage of the structure to have the slug set to exactly __home__ which will cause the URI to evaluate to __home__, and Craft will then consider that the homepage. Then all of the Content SEO settings you have for the structure will work, as will any SEOmatic fields on the structure. Discussed here: https://craftcms.stackexchange.com/questions/1467/add-home-page-to-a-structure

2) You can set up a Single for the Homepage and then configure the Content SEO settings for that as you see fit in SEOmatic -> Content SEO

3) You can keep everything the way you've structured it, and manually set the SEOmatic settings via Twig as per: https://github.com/nystudio107/craft-seomatic#twig-templating

khalwat commented 6 years ago

It's also possible that this will help you as well:

{% set home = craft.entries.slug('homepage') %}
{% do seomatic.helper.loadMetadataForUri(home.uri) %}

That should load up everything you want for ya. https://github.com/nystudio107/craft-seomatic#helper-functions-seomatichelper

proximo7 commented 6 years ago

Thanks so much for this help. I tried the last method {% set home = craft.entries.section('pages').id('39') %} {% do seomatic.helper.loadMetadataForUri(home.uri) %}

And got: Argument 1 passed to nystudio107\seomatic\services\Helper::loadMetadataForUri() must be of the type string, null given, called in /home/neder/craft3/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1619

I'll try the other methods too.

khalwat commented 6 years ago

Oh, that must be because that entry has no public URI? If so, yeah, you'll have to try other methods.

bryantAXS commented 6 years ago

@khalwat I believe I'm running into this issue as well.

It's a Structure with a homepage designated by the __home__ slug. When I visit the page, data from the SEO field isn't being pulled in.

It sounds like you're mentioning the plugin should be compensating for this already?

https://cl.ly/b13444bec83c

bryantAXS commented 6 years ago

False alarm, it looks like it was potentially a caching issue? I cleared them and now I'm seeing it work correctly.