Custom WP TItle from custom template with dynamic URL structure

I am new to custom WP development, but I have made a custom plugin.

With a custom rewrite I have made the following URL structure:
/profile/[company_name]/

I have made a new post Profile with a custom template (page-profile.php).
I created a WordPress Plugin which gets external info based on the dynamic url.

So I get info for [company_name] and have this data available in the custom page-profile.php.

With the following code, everything is set:

update_post_meta(get_the_ID(), '_yoast_wpseo_title', self::$data['seo']['seo_title'].' -'.time());
update_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', self::$data['seo']['seo_description']);
add_filter('wp_title', self::$data['seo']['title']);

But the problem is the page rendering. First header.php gets parsed, then the theme. Because the URL is dynamic (and WordPress only knows post.php?post_id=9999), on all pages it shows the same title.
When reloading it get’s the right title.

The question:

How can I set the meta / wp_title before Yoast WP SEO / wp_title are being rendered?

  • I can make a custom filter in de functions.php, but how can i make my data from the plugin available in the functions.php?

Thanks!

0

Leave a Comment