Skip to content

Instantly share code, notes, and snippets.

@simonrcodrington
Last active October 16, 2017 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonrcodrington/a8e2e966188167def356212673af089e to your computer and use it in GitHub Desktop.
Save simonrcodrington/a8e2e966188167def356212673af089e to your computer and use it in GitHub Desktop.
Sample function to remove the archive pages from post categories / tags. Useful if you want to disallow access
/**
* Adjusts taxonomies to remove their index page (archive page)
*
* Removing the 'publicly_queryable' property and setting 'rewrite' to false to disallow direct URL linking to the name of the term (no archive page
* needed). requires permalinks once to get this to work.
*
* @param $args - Arguments used to register taxonomy
* @param $taxonomy_name - Taxonomy Key
* @param $object_type - Array of names of object types for the taxonomy
*/
function remove_archives_for_taxonomies($args, $taxonomy_name, $object_type){
if($taxonomy_name == 'post_tag' || $taxonomy_name == 'category'){
$args['publicly_queryable'] = false;
$args['rewrite'] = false;
}
return $args;
}
add_action('register_taxonomy_args', 'remove_archives_for_taxonomies', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment