I'm trying to access the value set for my optimized title within Sprout SEO. I've had a read through this page: https://sprout.barrelstrengthdesign.com/craft-plugins/seo/docs/advanced-customization/custom-metadata-variable - but have had no luck.

Why I want to do this is because I'm loading my pages via AJAX and need to set the title once the content is loaded. I've tried various iterations of {{ entry.metadata.metadata.optimizedTitle }} but to no avail.

Alternately, do you know how to set the metadata to update upon each AJAX page load?


So to update this question incase someone happens to stumble across it.

With Sprout SEO you need to enable the Enable custom metadata variable option under 'Advanced' in the settings menu.

From there I set a twig variable with the value of my metadata title, in this case {%- set metaTitle = entry.metadata.title -%} and attach it to my AJAX wrapper element with something like data-title="{{ metaTitle }}".

Now when I load each page via javascript I just do a little something like this document.title = $('<div />').append(html).children('.js-ajax-wrapper').data('title'); once the content is loaded in and my page title is updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.