Answers.Body: <p>So to update this question incase someone happens to stumble across it.</p>
  
  <p>With Sprout SEO you need to enable the <code>Enable custom metadata variable</code> option under 'Advanced' in the settings menu. </p>
  
  <p>From there I set a twig variable with the value of my metadata title, in this case <code>{%- set metaTitle = entry.metadata.title -%}</code> and attach it to my AJAX wrapper element with something like <code>data-title="{{ metaTitle }}"</code>.</p>
  
  <p>Now when I load each page via javascript I just do a little something like this <code>document.title = $('&lt;div /&gt;').append(html).children('.js-ajax-wrapper').data('title');</code> once the content is loaded in and my page title is updated.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-03T18:55:28.927Z
Answers.LastActivityDate: 2017-04-03T18:55:28.927Z
Answers.UserDisplayName: rjdvsk
Body: <p>I'm trying to access the value set for my optimized title within Sprout SEO. I've had a read through this page: <a href="https://sprout.barrelstrengthdesign.com/craft-plugins/seo/docs/advanced-customization/custom-metadata-variable" rel="nofollow noreferrer">https://sprout.barrelstrengthdesign.com/craft-plugins/seo/docs/advanced-customization/custom-metadata-variable</a> - but have had no luck.</p>
  
  <p>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 <code>{{ entry.metadata.metadata.optimizedTitle }}</code> but to no avail. </p>
  
  <p>Alternately, do you know how to set the metadata to update upon each AJAX page load?</p>
  
Tags: <ajax><plugin-sproutseo><meta>
Title: Access optimizedTitle field within Twig template
ThreadText: # Access optimizedTitle field within Twig template
  
  (Asked by: username_0 on 2017-03-29)
  
  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?
  
  **Tags:** ajax, plugin-sproutseo, meta
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-04-03. Score: 1
  
  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.
  
  
  ---
  
  