• Resolved ChromaDot

    (@soojooko)


    Firstly – great plugin. Clean and unbloated, unlike others I won’t mention.

    It works perfectly on most of my websites. However, one of my sites is a single page website which dynamically loads pages/content via AJAX. I would like to be able to dynamically update metadata ( such as title and description ) when I load in a new page. The pages all exist ( as a fallback in case I want to disable the dynamic loading ) and they all have their own metadata defined using your plugin. But obviously, when I turn my dynamic loading features on, all the meta stays the same with each page load – as defined by the first page that was loaded in the browser.

    Hope this makes sense?

    Any advice you can offer would be appreciated?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hi there! Thanks ??

    Dynamically updating metadata is tricky, but it is why the WordPress REST API is helpful as it allows you to obtain parts of the page.

    I haven’t tried so myself, but I believe you’d want to call the wp_head() function, and refill the header from the response. Both WordPress and TSF hook therein to output the title and metadata.

    It’s not the cleanest solution, but I have yet to embrace REST, and I want to transform my sites to be REST-powered. So, you can expect better compatibility in the future.

    If you’d rather have direct callbacks and work from there, here they are:

    if ( function_exists( 'the_seo_framework' ) && the_seo_framework()->loaded ) {
    	$title = the_seo_framework()->get_document_title(); // if this leads to an error, use ->get_title().
    	$meta  = the_seo_framework()->html_output();
    }

    I hope this helps! Again, I have yet to embrace REST; so, feel free to follow up if this wasn’t the answer you were looking for.

    Thread Starter ChromaDot

    (@soojooko)

    Thanks for the response. Regards your direct callback solution – wont that simply return the meta from the landing page? If I click on one of my links, which loads a new page dynamically, how does TSF know which page has just been loaded in? Your snippet doesn’t allow for setting of a page ID. Is there no way to tell the TSF class to fetch the meta from a particular page?

    Having said that, your head refill solution gives me an idea: When looking at the HTML which is dynamically loaded with my code, the entire <head> of the incoming page is included. I guess I could take that and refill the existing head section. That might be worth trying if I can’t fetch the meta using the TSF class.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hello again!

    If the WP_Query instance for the new page is processed correctly, then TSF can generate all its meta tags accordingly. So, if the wp_head() call works as intended, then I assume this is the case ??

    However, if that’s not the case, then you can process each tag individually. In the past few major releases, I’ve transformed generation-methods of the plugin to work better in the back-end (where there’s no WP_Query), which directly benefits REST scenarios, too.

    Unfortunately, due to the slow pace in adoption of the REST API within themes, I’m not sure whether there’s already a standard available for processing and forwarding this data. That said, feel free to reach out if you’re finding difficulties.

    Thread Starter ChromaDot

    (@soojooko)

    I understand. I’ve managed to get it working. Thank you! Your help is most appreciated. ??

    Really nice plugin. Keep up the great work!

    Plugin Author Sybre Waaijer

    (@cybr)

    Awesome! Would you mind sharing how you’ve got it working, so I can keep that in mind before I start changing things in the future? Cheers ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Single page websites – dynamically update meta’ is closed to new replies.