Site logo

Archived topic

Point a WordPress Category URL to a Custom Category Page

7 replies · Started by Glenda on April 21, 2021

Viewing posts 1–8 of 8

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?

Hi 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-slug with 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.

Thanks, Elvin. Just to clarify, the only thing I am changing in the filter is the your-category-slug, right?

Yes 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.

I appreciate all your help, Elvin. I haven't been able to make it work tonight, but Ill keep studying it. Thank you!

No problem. :)

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

This archived topic is closed to new replies.