Site logo

Archived topic

Category archive pages, URL

3 replies · Started by Ted on December 7, 2022

Viewing posts 1–4 of 4

Greetings,

I've changed my archive pages to static pages with the PHP at the bottom here. (as suggested in this forum)

I've changed the canonical links to static URLs without the word 'category' in them, but they keep showing up as something like https://thegreatestsong.com/category/audio-gear-reviews/
What I would like is:
https://thegreatestsong.com/audio-gear-reviews/

I've obviously missed some key step here which removes category from the URL. Your help would be most appreciated.

Kind Regards

PHP snippet I'm using:

add_filter('request', function( array $query_vars ) {
    if ( is_admin() ) {
        return $query_vars;
    }

    if ( isset( $query_vars['category_name'] ) ) {
        $pagename = $query_vars['category_name'];

        $query_vars = array( 'pagename' => "$pagename" );
    }

    return $query_vars;
} );

Hi there,

Can you go to admin > settings > permalinks, in the Category base field, enter a ., then save the changes?

Let me know if this works.

Worked! Many thanks!

No problem :)

This archived topic is closed to new replies.