Skip Navigation

[Resolved] How to remove taxonomy pages

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to disable their taxonomy archives.

Solution:

This can be done with the code below.

/**
* Disable the taxonomy archive pages
*/
add_action('pre_get_posts', 'jb_disable_tax_archive');
function jb_disable_tax_archive($qry) {
  
    if (is_admin()) return;
  
    if (is_tax('tax-slug')){
        $qry->set_404();
    }
  
}

Add the above to your custom code section in Toolset -> Settings -> Custom Code and ensure that you've activated the code.

Finally change the 'tax-slug' to the slug of the taxonomy that you want to disable the archive for.

This support ticket is created 3 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 2 voices.

Last updated by nickW-7 3 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#2000999

Tell us what you are trying to do?
I created a custom post and added taxonomies to that post. One of those taxonomies is called 'ministers' and it has 'Taylor Walling' as an item. A page for 'Taylor Walling' was automatically created and I didn't know it existed until someone pointed it out because they did a google search and clicked on it. Is it possible to remove that page? If not, then how can I access the page to style it?

Is there any documentation that you are following?
No

Is there a similar example that we can see?
No

What is the link to your site?
hidden link

#2001099

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nick,

Thank you for getting in touch.

Unfortunately the only way to disable this is with the use of some form of custom code.

Add the following to the Toolset custom code section in Toolset -> Settings -> Custom Code


/**
* Disable the taxonomy archive pages
*/
add_action('pre_get_posts', 'jb_disable_tax_archive');
function jb_disable_tax_archive($qry) {
 
    if (is_admin()) return;
 
    if (is_tax('tax-slug')){
        $qry->set_404();
    }
 
}

Then activate it. Ensure that you've replaced 'tax-slug' with the actual slug of your taxonomy.

Please let me know if this helps.
Thanks,
Shane

#2001111
Screen Shot 2021-03-25 at 4.13.08 PM.png

Is this correct? (see attachment) I activated it and tried going to the page again (hidden link) but it's still active.

#2001141

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nick,

I'm assuming here that Minister is the Taxonomy and Taylor walling is the term.

If such is the case then the code you should be adding is

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

/**
* Disable the taxonomy archive pages
*/
add_action('pre_get_posts', 'jb_disable_tax_archive');
function jb_disable_tax_archive($qry) {
  
    if (is_admin()) return;
  
    if (is_tax('minister')){
        $qry->set_404();
    }
}

Please let me know if this works now.
Thanks,
Shane

#2001161

My issue is resolved now. Thank you!