- This topic has 18 replies, 4 voices, and was last updated 7 months ago by
David.
-
AuthorPosts
-
January 2, 2019 at 3:13 am #770914
Isaac
Hi,
I’m trying to use as few plugins as possible on my site.
Is there any way I can add categories to pages using GeneratePress out of the box? (I’ve searched docs)
I know there is a bazzilion plugins that will do this, but I’m trying to keep Plugin use to a bare minimum, so that my site remains lightweight.
thanks
January 2, 2019 at 9:07 am #771270Leo
StaffCustomer SupportHi there,
David provided some valuable suggestion here:
https://generatepress.com/forums/topic/adding-categories-and-tags-taxonomy-to-pages/You can find lots of information on CPT in Google
If you still prefer to use categories, then plugin is the way to go 🙂
January 3, 2019 at 6:40 am #771943André
Isaac, this has worked for me:
Using the Code Snippets plugin (which I already use), I added this code:
function add_taxonomies_to_pages() { register_taxonomy_for_object_type( 'post_tag', 'page' ); register_taxonomy_for_object_type( 'category', 'page' ); } add_action( 'init', 'add_taxonomies_to_pages' ); if ( ! is_admin() ) { add_action( 'pre_get_posts', 'category_and_tag_archives' ); } function category_and_tag_archives( $wp_query ) { $my_post_array = array('post','page'); if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) ) $wp_query->set( 'post_type', $my_post_array ); if ( $wp_query->get( 'tag' ) ) $wp_query->set( 'post_type', $my_post_array ); }
Once added to Code Snippets, enable. That’s it. Categories will show for pages, no different to posts.
I originally tried to add the code using GP > Elements, but couldn’t figure it out. But Code Snippets works great.
January 3, 2019 at 7:40 am #772152Leo
StaffCustomer SupportThanks Andre!
January 4, 2019 at 2:06 am #772741Isaac
Thanks Andre.
In the end I just went with a plugin.
The plugin was really small, like 2.1KB so wouldn’t have bloated out my
site and it was simple.Cheers
January 4, 2019 at 2:32 am #772749André
Isaac, which plugin did you go with?
January 4, 2019 at 4:46 am #772805Isaac
May 30, 2020 at 5:21 am #1307503Whelan
Hello
I’m also looking for a lightweight way to use post categories for pages too. I’ve added the relevant php to code snippets as mentioned above.
It’s working but the secondary navigation does not recognise the active category on a page. What am I missing?
May 30, 2020 at 10:42 am #1307937Tom
Lead DeveloperLead DeveloperDoes the primary navigation recognize it? If not, I assume WordPress is doing something else internally to make that connection. Have you tried the plugin mentioned above?
May 31, 2020 at 2:43 pm #1309152Whelan
I’m using the same code as the mentioned plugin, in the same way that the plugin developer describes here:
https://thewphosting.com/add-categories-tags-pages-wordpress/The primary navigation does recognise it, but I need it to work in the secondary nav. Is this possible?
June 1, 2020 at 5:09 am #1309690David
StaffCustomer SupportHi there,
can you share a link to your site ? You may want to start a new topic where you can share the link privately using the Site URL field provided.
June 2, 2020 at 11:08 am #1311634Whelan
OK thanks, I’ll start a new topic
June 25, 2021 at 12:22 am #1834325Marc
Looking for same kind of feature: using categories for pages, just like they can be used for blog posts and Woo products.
But more important: the categories need to be used in the permalink structure too – just as with posts and products.
For example, if the categories are:
= wall art
== living room
=== canvas print (in this example the checked category)
=== fine art print
=== etcThen the slug need to become: /wall-art/living-room/canvas-print/page-title
Does anyone know if a plugin like Add categories to pages makes that possible?
June 25, 2021 at 3:41 am #1834475David
StaffCustomer SupportHi there,
to the best of my knowledge you cannot create the category slug permalink structure for Pages. But you can use Sub Pages to do the same thing:
https://wordpress.org/support/article/pages/#organizing-your-pages
June 25, 2021 at 3:53 am #1834490Marc
Thnx for the reply! 🙂
Yes, I now about the parent child structure, creating a permalink structure/hierarchy.
Wondering why WP created such a thing for posts, but not for pages…
-
AuthorPosts
- You must be logged in to reply to this topic.