How to customize the Categories on the Post(post.php)

This will customize way the Categories select to restrict on the Add New Post and Edit Post.

 

 

Over limit Categories alert

Over limit Categories alert

 

 

 

 

Step1 Remove the Categories Metabox of Core.

 

Please add code to the functions.php of your theme.

 

It looks like this.

 

Remove Categories metabox of Core

Remove Categories metabox of Core

 

 

 

Step2 Add the new custom categories metabox.

 

Please add code to custom_load_post function.

 

And please add code to functions.php.

 

It looks like this.

 

Add Custom Categories metabox

Add Custom Categories metabox

 

 

 

 

If you want to be only one select

 

Please change the code to custom_category_metabox function.

 

It looks like this.

 

Choose to Categories of radio button

Choose to Categories of radio button

 

Or if you want to select box.

 

It looks like this.

 

Choose to Categories of select box

Choose to Categories of select box

 

 

 

If you want to be only select the child categories

 

This will change the value of the parent of get_categories().

e.g.)

 

The code looks like this.

 

 

Show only child Categories

Show only child Categories

 

 

 

If you want to limit the category check number

 

Categories check number validation to Javascript.

Please add code to custom_load_edit function.

 

And please add code to functions.php.

 

And please add code to create the  custom-categories.js of your theme directory.

 

It look like this.

 

Over limit Categories alert

Over limit Categories alert

 

 

This is complete! 🙂

 

Full code is here.

 

PHP

 

Javascript

 

 

 

Leave a Reply

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


*