- This topic has 7 replies, 4 voices, and was last updated 5 years ago by
David.
-
AuthorPosts
-
April 21, 2021 at 7:24 pm #1743915
Glenda
I have created a custom category page layout that I like. https://glendaembree.com/category/chicken
It is, however, just a page. Is there any way, now that it’s created to point the actual category in WordPress/GP to that new url?
The page automatically created by WordPress/GP for the category is https://glendaembree.com/category/main-dish. I have not found any way to edit it’s layout to something simple like I’ve done with the first link. Is it even possible to change the url a category points to?
April 21, 2021 at 9:28 pm #1743977Elvin
StaffCustomer SupportHi there,
Can you try this filter?
add_filter('request', function( array $query_vars ) { if ( isset( $query_vars['category_name'] ) ) { $pagename = $query_vars['category_name']; if ( $pagename != 'your-category-slug') { $query_vars = array( 'pagename' => "$pagename" ); } } return $query_vars; } );Change the part
your-category-slugwith the category slug of you’re trying to point to the static page. Make sure the page slug or “pagename” and the category slug are the same.April 21, 2021 at 10:36 pm #1744032Glenda
Thanks, Elvin. Just to clarify, the only thing I am changing in the filter is the your-category-slug, right?
April 21, 2021 at 10:45 pm #1744041Elvin
StaffCustomer SupportYes that’s right.
Example:
add_filter('request', function( array $query_vars ) { if ( isset( $query_vars['category_name'] ) ) { $pagename = $query_vars['category_name']; if ( $pagename != 'main-dish') { $query_vars = array( 'pagename' => "$pagename" ); } } return $query_vars; } );Let us know how it goes.
April 21, 2021 at 11:01 pm #1744060Glenda
I appreciate all your help, Elvin. I haven’t been able to make it work tonight, but Ill keep studying it. Thank you!
April 22, 2021 at 6:30 pm #1745359Elvin
StaffCustomer SupportNo problem. 🙂
May 14, 2021 at 9:54 pm #1781053kasei
Hey, sorry to jump in. Thanks for the code!
Is there a quick solution so that it automatically looks for the page instead (or list each category in the same filter)? I’m thinking if we have like 10 or 15 categories, seems like a lot of extra code to copy that whole filter over and over.
Cheers
May 15, 2021 at 4:38 am #1781372David
StaffCustomer SupportHi there,
the original code can be found here:
https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/
This ‘redirects’ all Categories to a Page with the same name.
-
AuthorPosts
- You must be logged in to reply to this topic.