Split: Can I use a filter hook to modify the contents of the section?
-
[Moderator Note: This topic was split off from https://www.ads-software.com/support/topic/can-i-use-a-filter-hook-to-modify-the-contents-of-the-section/ ]
Hey guys, on single posts and pages there should already be a canonical meta link in your head section. You don’t want to add another one. It defeats the purpose and makes for bad SEO if they are different.
We can alter the canonical link that is already there with the “get_canonical_url” filter. You filter callback is passed the URL WP wants to use, plus the post object being displayed. You can get the post date from the post object and alter the URL when required. From what I gather, the cutoff is the date when the old HTTP URL was no longer valid. If you don’t recall when that happened, perhaps looking at your SSL certificate’s expiration date will help. Work backwards based on how long the certification was supposed to be good for.
How you would selectively alter the OpenGraph tag depends on how it is generated in the first place. Since OG tags are not part of the default WP distribution, I cannot comment on that aspect.
The above sort of filter code is usually added to a custom child theme’s functions.php. In the case of a commercial child theme based on a framework, this is not a good choice. However, this code works equally well from a custom site specific plugin. You can place any other custom code you might want to create in this same plugin.
@davidborrink — it appears part of you post was cut off for some reason. If I haven’t completely answered your questions, go ahead and ask.
- The topic ‘Split: Can I use a filter hook to modify the contents of the section?’ is closed to new replies.