Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove taxonomies
<?php
add_action( 'pre_get_posts', 'cameronjonesweb_404_tag_archives' );
function cameronjonesweb_404_tag_archives( $query ) {
if( $query->is_main_query() && $query->is_tag() ) {
$query->set_404();
status_header( 404 );
}
}
<?php
add_action( 'init', 'cameronjonesweb_unregister_categories' );
add_filter( 'get_the_categories', '__return_false' );
add_filter( 'the_category', '__return_false' );
add_filter( 'wp_get_object_terms', 'cameronjonesweb_hide_categories_front_end', 10, 4 );
add_action( 'pre_get_posts', 'cameronjonesweb_404_category_archives' );
/**
* Removes categories from blog posts
*/
function cameronjonesweb_unregister_categories() {
unregister_taxonomy_for_object_type( 'category', 'post' );
}
/**
* Removes categories from the front end
*/
function cameronjonesweb_hide_categories_front_end( $terms, $object_ids, $taxonomies, $args ) {
if( in_array( 'category', $taxonomies ) ) {
$terms = false;
}
return $terms;
}
/**
* Remove category pages
*/
function cameronjonesweb_404_category_archives( $query ) {
if( $query->is_main_query() && $query->is_category() ) {
$query->set_404();
status_header( 404 );
}
}
<?php
add_filter( 'get_the_tags', '__return_false' );
add_filter( 'the_tags', '__return_false' );
add_filter( 'wp_get_object_terms', 'cameronjonesweb_hide_tags_front_end', 10, 4 );
function cameronjonesweb_hide_tags_front_end( $terms, $object_ids, $taxonomies, $args ) {
if( in_array( 'post_tag', $taxonomies ) ) {
$terms = false;
}
return $terms;
}
<?php
add_action( 'init', 'cameronjonesweb_unregister_tags' );
/**
* Removes tags from blog posts
*/
function cameronjonesweb_unregister_tags() {
unregister_taxonomy_for_object_type( 'post_tag', 'post' );
}
<?php
add_action( 'init', 'cameronjonesweb_unregister_woocommerce_taxonomies' );
add_filter( 'wp_get_object_terms', 'cameronjonesweb_hide_woocommerce_taxonomies_front_end', 10, 4 );
add_action( 'pre_get_posts', 'cameronjonesweb_404_woocommerce_taxonomy_archives' );
/**
* Removes tags and categories from WooCommerce products
*/
function cameronjonesweb_unregister_woocommerce_taxonomies() {
unregister_taxonomy_for_object_type( 'product_cat', 'product' );
unregister_taxonomy_for_object_type( 'product_tag', 'product' );
}
/**
* Removes WooCommerce taxonomies from the front end
*/
function cameronjonesweb_hide_woocommerce_taxonomies_front_end`( $terms, $object_ids, $taxonomies, $args ) {
if( in_array( [ 'product_cat', 'product_tag' ], $taxonomies ) ) {
$terms = false;
}
return $terms;
}
/**
* Remove WooCommerce taxonomy archives
*/
function cameronjonesweb_404_woocommerce_taxonomy_archives( $query ) {
if( $query->is_main_query() && $query->is_term( [ 'product_cat', 'product_tag' ] ) ) {
$query->set_404();
status_header( 404 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.