Create a custom taxonomy’s term form

WordPress does not provide a hook or any API/function which allows us to move that form, or prevent it from being generated and added to the HTML source.

But if you just wanted to visually hide that form, then it can easily be done using CSS, e.g.

body.wp-admin.edit-tags-php #col-left {
    /* Hide the default form for adding a new term. */
    display: none;
}

body.wp-admin.edit-tags-php #col-right {
    /* Make the list table displays in full-width. */
    width: 100%;
}

And despite that there’s no core function which gives us just that form, you could actually just create a standard/simple form with the following fields, and then use wp_insert_term() to create a term from the submitted form data.

  1. The form fields and their name:

    Form Field name
    Term Name tag-name
    Term Slug slug
    Parent Category parent
    Description description

    That might change in future WordPress releases, but then you could always inspect the form element using the browser’s dev tools, e.g. like so on Chrome:

    Screenshot 1

  2. When the form is submitted, run this: (it’s up to you on defining the $taxonomy variable)

    wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST )
    

That’s basically how WordPress does it on the edit-tags.php page, but be sure to add an nonce field and apply other security measures as documented here.

As for where to submit the form to, you can submit it to the very same page, but I’d probably use admin-post.php and then use the admin_post_<action> hook to process the submission.

  • Or you can use AJAX and the relevant REST API endpoint, but sorry, these two are not in scope of this answer.

Remember though, that I was just guiding you on how could you create a form similar to the default form which you’re trying to move, but I was not encouraging you to disable/hide that form.

  • If you didn’t like the form’s appearance, then use CSS to make the form look better, and you could also utilize JavaScript to reposition the elements in that form and/or the page.

  • If you wanted to add some custom HTML before or after the form, then make use of the hooks run on that page, e.g. <taxonomy>_pre_add_form.

  • And if you were actually trying to achieve something like this (which adds a submenu that links to the edit-tags.php page for a specific taxonomy, or displays that page under your plugin page), then that can be done using the parent_file filter. (code sample available upon request)

tech