Last active
October 16, 2017 01:30
-
-
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
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
/** | |
* 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