Last active
July 17, 2018 12:41
-
-
Save cameronjonesweb/4a3034e73a8336d46a813edfcd9ebcd6 to your computer and use it in GitHub Desktop.
Remove taxonomies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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