How can I modify the functions file to show a distinct SEO title (sourced from a Yoast SEO field) on the frontend that differs from the URL title, while exempting specific post IDs?
In my experience, the optimal approach is to leverage existing WordPress hooks such as the ‘wpseo_title’ or ‘the_title’ filters instead of directly altering the core output. I used get_post_meta to retrieve the Yoast SEO field, and then conditionally checked for the excluded post IDs before applying the modification. This method keeps my solution organized and ensures compatibility with Yoast updates. A careful use of these hooks makes it easy to maintain the distinction between the frontend SEO title and the URL title.
i tried a custom filter approach similar to this before and it worked well. make sure to account for caching tho, any issues here? isn’t it fun tinkering with wp filters to get just the right output? what challenges have you faced with meta data integration?
i’d try using the ‘document_title_parts’ filter. it lets u swap the title part for non exempt posts by fetching yoast meta directly. it seems to wrk robustly and might suit your needs.