Home › Forums › Pro Support › Use Static Pages as Category Archives
- This topic has 12 replies, 4 voices, and was last updated 2 years, 1 month ago by
elvin.
-
AuthorPosts
-
July 24, 2019 at 11:14 am #10428
Ericka
ParticipantHi!
I follow the instructions in “Use Static Pages as Category Archives” documentation. And everything in good! But im wondering:– Do I have to NOINDEX my category pages?
– Do I have to make a redirection?
– Is there gonna be duplicate content?July 24, 2019 at 5:55 pm #10440Tom
KeymasterHi there,
I believe the code in that article does the redirection for you. The old category pages shouldn’t be accessible if you type them into your address bar.
However, if you’re worried, it doesn’t hurt to set up a 301 redirect from the old category archives to the new pages. This will make sure all three of those points are dealt with.
July 24, 2019 at 7:36 pm #10446Ericka
ParticipantOk thanks!!
July 25, 2019 at 8:09 pm #10459Tom
KeymasterNo problem ๐
July 30, 2019 at 1:52 pm #10525Ericka
ParticipantHi! Is me again!
Is there a way to exclude some categories when the function is active? I dont want all my categories to be static pages, just the “important” ones for SEO purposes.
July 30, 2019 at 4:57 pm #10527Tom
KeymasterTry this:
add_filter('request', function( array $query_vars ) { if ( is_admin() ) { return $query_vars; } $targets = array( 'My name here', 'Another', 'One More Name', ); if ( isset( $query_vars['category_name'] ) && in_array( $query_vars['category_name'], $targets ) ) { $pagename = $query_vars['category_name']; $query_vars = array( 'pagename' => "$pagename" ); } return $query_vars; } );
Then adjust the names of the categories you want to target in the
$targets
array.July 30, 2019 at 6:33 pm #10533Ericka
ParticipantYou mean here:
$targets = array(
‘My name here’,
‘Another’,
‘One More Name’,
);But how I adjust the names of the categories? For example, if I have a category with this URL: /category/books/ and a page just: /books/, how i put the name in the code? ๐
July 31, 2019 at 4:30 pm #10540Tom
KeymasterIf your category name is “Books”, you would do this:
$targets = array( 'Books', );
July 31, 2019 at 7:40 pm #10543Ericka
ParticipantOk perfect!! Thanks again ๐
August 1, 2019 at 3:34 pm #10558Tom
KeymasterYou’re welcome ๐
April 1, 2021 at 1:36 pm #28750TWarrior
ParticipantHello,
This is not working for me:
add_filter('request', function( array $query_vars ) { if ( is_admin() ) { return $query_vars; } $targets = array( 'Biblio', ); if ( isset( $query_vars['category_name'] ) && in_array( $query_vars['category_name'], $targets ) ) { $pagename = $query_vars['category_name']; $query_vars = array( 'pagename' => "$pagename" ); } return $query_vars; } );
– I have a “Biblio” page and a “Biblio” category.
– If I remove the “&& in_array( $query_vars[‘category_name’], $targets )” code (using the default code in https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/ ) It is works perfectly.What am I missing?
April 1, 2021 at 1:50 pm #28753TWarrior
ParticipantI have make it works only if:
1. I use the slug “biblio”, not the name “Biblio”.
AND
2. The category has no “Parent Category”But i need the parent category…
April 6, 2021 at 8:21 pm #28924elvin
ModeratorHi there,
category_name
takes the slug, not the actual Label/name.
https://developer.wordpress.org/reference/classes/wp_query/#category-parametersโBiblioโ is a label/name. โbiblioโ is a slug, that’s why it works.
-
AuthorPosts
- You must be logged in to reply to this topic.