Dear generatepress-team,
first of all thanks for developing such a great theme!
My request: I would like to enable tags for pages without creating an archive page for them.
FYI:
– I’ve informed myself on CPTs as well and in this case tags would be more handy for me.
– I’m aware that there are also plugins for my request, but I try limiting the plugin usage.
– My goal is to add tags to pages in a way that I can configure consistent display rules for different page templates (hero sections for instance) + for related posts queries – the used page builder is elementor -> so in short: the tags should just work in the background to establish relationships between different pages.
So after my “research” I have found the following snippet, that I would like to add to my child theme’s function php – to be safe I would be glad if you could have a look on the code before I implement it:
// add tag support to pages
function tags_support_all() {
register_taxonomy_for_object_type(‘post_tag’, ‘page’);
}
// ensure all tags are included in queries
function tags_support_query($wp_query) {
if ($wp_query->get(‘tag’)) $wp_query->set(‘post_type’, ‘any’);
}
// tag hooks
add_action(‘init’, ‘tags_support_all’);
add_action(‘pre_get_posts’, ‘tags_support_query’);
A short description of what the different parts of the code are doing would also be awesome.
Thanks a lot and best regards from Germany,
Ralph