How to remove child selection when adding or editing taxonomies for custom post type

Building

Quick summary

Easily remove child selection when editing taxonomies for custom post types in WordPress. Use simple jQuery code for seamless customization.

How to remove child selection when adding or editing taxonomies for custom post type

add_action( ‘admin_head-edit-tags.php’, ‘remove_child_taxonomy_selection_box’ );

function remove_child_taxonomy_selection_box()
{
// don’t run in the Tags screen
if ( ‘customposttype_name’ != $_GET[‘taxonomy’] )
return;

// Screenshot_1 = New Category
// http://example.com/wp-admin/edit-tags.php?taxonomy=category
$parent = ‘parent()’;

// Screenshot_2 = Edit Category
// http://example.com/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=17&post_type=post
if ( isset( $_GET[‘action’] ) )
$parent = ‘parent().parent()’;
?>

jQuery(document).ready(function($)
{
checkval();
$(“#parent”).live(‘click’,function(){
checkval();
});
});
function checkval()
{
jQuery(“#parent option”).each(function(index){
if(!jQuery(this).hasClass(‘level-0’))
{
jQuery(this).remove();
}
});
}

<?php
}

Date: May 21, 2014
|

Leave a reply

Your email address will not be published. Required fields are marked *