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

JSON-LD not working with meta-tags.templates #13

Open
HashandSalt opened this issue Jul 31, 2019 · 7 comments
Open

JSON-LD not working with meta-tags.templates #13

HashandSalt opened this issue Jul 31, 2019 · 7 comments

Comments

@HashandSalt
Copy link

HashandSalt commented Jul 31, 2019

As the title says. If you set JSON-LD up in meta-tags.default it comes out on every page. If you want a different schema on a specific page (in my case blog post schema), this block also comes out on every page, despite being set within meta-tags.templates for a specific page template.

Other properties in meta-tags.templates work as expected, seems limited to just JSON-LD.

How can I make this work?

@pedroborges
Copy link
Owner

Could you please share just the JSON-LD settings to reproduce this?

@HashandSalt
Copy link
Author

HashandSalt commented Jul 31, 2019

Sure, here you go...

// Meta Tags
'pedroborges.meta-tags.default' => function ($page, $site) {

    $contact = $site->index()->find('hire-a-great-digital-marketing-agency');
    $logo = $site->sitelogo()->toFile() ? $site->sitelogo()->toFile()->url() : '';
    $location = $contact->locmap()->toLocation();

    return [
      'json-ld' => [
          'LocalBusiness' => [
              'name' => $contact->businessname()->value(),

              'url' => $site->url(),
              "email" => $contact->emailaddress()->value(),
              "logo" => $logo,
              "description" => $contact->businessdescription()->value(),
              "sameAs" => [socialprofiles()],
              "telephone" => $contact->telephone()->value(),
              "priceRange" => "£££ - ££££££",
              "openingHours" => [$contact->hours()->value()],
              "address" => [
                "@type" => "PostalAddress",
                "streetAddress" => $contact->streetaddress()->value(),
                "addressLocality" => $contact->addresslocality()->value(),
                "addressRegion" => $contact->addressregion()->value(),
                "postalCode" => $contact->postalcode()->value(),
              ],
              "geo" => [
                "@type" => "GeoCoordinates",
                "latitude" =>  $location->lat()->value(),
                "longitude" => $location->lon()->value(),
              ],
              'image' => $site->find('web-design-client-work')->heroslidesfield()->toFiles()->shuffle()->first()->url(),
          ]
      ],


},

'pedroborges.meta-tags.templates' => function ($page, $site) {

  $logo = $site->sitelogo()->toFile() ? $site->sitelogo()->toFile() : '';

  return [
      'blog' => [

        'json-ld' => [
            'BlogPosting' => [
              'mainEntityOfPage' => [
                '@type' => 'WebPage',
                '@id' => $page->url()
              ],
              'headline' => $page->seotitle()->value(),
              'image' => [
                '@type' => 'ImageObject',
                  'url' => $page->images()->filterBy('feature', true)->first()->focusCrop(1280, 720)->url(),
                  'width' => 1280,
                  'height' => 720
        
              ],
              'datePublished' => $page->date()->toDate('Y-d-m'),
              'dateModified' => $page->modified('Y-d-m'),
        
        
              'author' => [
                '@type' => 'Person',
                  'name' => 'Person Name',
        
              ],
        
              'publisher' => [
                '@type' => 'Organization',
                  'name' => 'Hash&Salt',
                  'logo' => [
                    '@type' => 'ImageObject',
                      'url' => $logo->url(),
                      'width' => $logo->width(),
                      'height' => $logo->height()
        
                    ],
        
              ],
              'description' => $page->seometa()->value(),
            ]
        ],

    ],

  ];

},

@pedroborges
Copy link
Owner

pedroborges commented Jul 31, 2019

I'm not knowledgeable about JSON-LD, I see that it includes both the LocalBusiness and BlogPosting schemas on blog templates. Is that the issue? Should the plugin include only BlogPosting in blog templates?

@HashandSalt
Copy link
Author

HashandSalt commented Jul 31, 2019

Yes :)

On every page and BlogPosts, i need the i need the LocalBusiness schema. On BlogPosts ONLY i need BOTH the LocalBusiness and BlogPost Schemas.

The plugin just needs to respect the schemas set in the meta-tags.templates config and not merge them with the default ones. They need to be done only on the template they have been set for.

@pedroborges
Copy link
Owner

Okay, I asked because it's already working like that on my side. See the image (simplified for testing purposes).

Screen Shot 2019-07-31 at 12 42 32

The plugin is including LocalBusiness on all pages and BlogPosting only in the template it's been defined.

@HashandSalt
Copy link
Author

HashandSalt commented Jul 31, 2019

Thats odd. For me, it loaded both on the home page. When I went back to the home page, i got a whoops message because it was looking for things that are not on the home. I just uncommented the code and tried again it seems to work. Both schemas were definetly coming out on the home page, i checked.

If i manage to trigger it again, i will post more detail. Probably some weird edge case, or something that your minimal test code is not triggering.

@HashandSalt
Copy link
Author

Ok - although im not getting both JSON blocks on the home page anymore, it is sill reading the config for the templates block on the home page and causing a whoops on an image call. It shouldnt be processing this part of the config unless the template matches.

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

2 participants