0

i would like to remove/hide the term form in the edit-tags.php page because i need to move it on another page. Is that possible somehow? Thanks

6
  • 1
    There are functions like wp_insert_term() that you could call to create a term in any taxonomy. So if you just wanted to be able to create a term via a custom form, there's no need to move that form. But I'm just curious, where did you intend to move the form to? What exactly is that "another page", what creates it, what's its URL, etc. Please add that details to your post.
    – Sally CJ
    Aug 2, 2023 at 11:09
  • Inside another admin.php page @SallyCJ
    – Dail
    Aug 2, 2023 at 15:25
  • 3
    Well, I was actually expecting you would edit your post and include the details I asked, or the answers to my questions. And as I said, you could just create a standard/simple form with a text input to enter the tag/category name, and then for example call wp_insert_term() (or maybe wp_create_tag() in wp-admin) when the input is submitted. Have you tried that? 🤔
    – Sally CJ
    Aug 3, 2023 at 14:26
  • no, i will give it a try. Thank you
    – Dail
    Aug 4, 2023 at 14:50
  • Could you please tell us why did you want to move that form? What's the benefit or true purpose of you doing so, or what does doing so solve? Are you doing this just for certain taxonomies like the core post_tag and category taxonomies? Did you use a plugin to add the another admin.php page, and was it your own plugin - if so, what's your code? If you answered all these, then I could probably write an answer to this question.
    – Sally CJ
    Aug 5, 2023 at 6:09

1 Answer 1

1
+150

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.