[Support request] Linking to custom category page

Home Forums Support [Support request] Linking to custom category page

Home Forums Support Linking to custom category page

  • This topic has 6 replies, 2 voices, and was last updated 2 years ago by David.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #1095460

    Looking to hard code links to my custom category pages and avoid the hop with a 301.

    I did something similar here with custom author pages – https://generatepress.com/forums/topic/linking-to-custom-author-archive/ which works great.

    is it possible to do something similar for categories?


    Customer Support

    Hi there,

    maybe this doc from WP Show Posts is what you’re looking for:



    Is it possible to adjust this code for when the slugs do not match?

    Customer Support

    Hmmm.. its not going to be automatic as the names need to be identical – could try conditionally checking a category name and setting a different page name like so:

    add_filter('request', function( array $query_vars ) {
        if ( is_admin() ) {
            return $query_vars;
        if ( isset( $query_vars['category_name'] ) ) {
            $pagename = $query_vars['category_name'];
            // Check for specicific category name
            if ( $pagename == 'category-slug') {
                // if specific category return specific page
                $query_vars = array( 'pagename' => "my-page-name" );
            } else {
                // else select page that has same name as category slug
                $query_vars = array( 'pagename' => "$pagename" );
        return $query_vars;
    } );

    I’m in the same boat with the need to use a page instead of the standard archive design.
    Using the above script works fine, but what I noticed is that posts within the category that has a static archive page don’t render the correct slug.


    “mydomain.com/category/widgets” uses a static page “widgets” in place of the regular category page.

    However, what happens is that a post “blue widgets” in the category “widgets” now renders this slug:

    whereas it should be




    Nevermind 😉

    The problem is actually a different one.

    When I use the script from here

    inside my functions.php, with my permalink settings to “custom structure: /%category%/%postname%/”

    the slug for a post in the category “widgets” will render


    That looks as intended, HOWEVER, the page that gets rendered under that slug is not the post content for “blue-widgets”, but the category page (which is using the static page as per enforced by the above script).

    Basically, it looks like URL for the post always redirects to the category page.
    I’m not using any SEO or redirection plugins, btw.

    Would you have any ideas why this is happening? 🙁

    Customer Support

    Hi there,

    could you raise a new topic where you can share a link to the site so we can take a look and see whats going on ?

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.