To add WordPress Terms on the front-end is a task that many WordPress users, developers, and designers often encounter, especially when building a dashboard for clients. Moxet Khan will guide you through the process of creating terms from the front-end using the JetFormBuilder, JetEngine, and Elementor. The tutorial will give you an idea of how this functionality can be applied in practical scenarios. The steps are easy to follow and are designed to help you understand how to use hooks to fetch one or multiple terms from form input and add them to the database.
How to Add WordPress Terms on the Front-end
- Create a Form Using Jet Form Builder
Go to your WordPress dashboard and create a new form using the JetFormBuilder. Name it “Add Terms”. Remove the default limits and add a text field named “Add New Subject”. - Define the Hook
In the JetForm settings, choose “Call Hook” as a “Post Submit Action”. Define the name of the hook, for example, “create_terms”. - Insert the Hook in function.php
Copy the action line provided by JetForm. You can insert the code using a child theme, a third-party plugin like Code Snippets, or directly paste it into your function.php.
In this case, we used the following code:add_action( ‘jet-form-builder/custom-action/create-terms’, function( $request, $action_handler ) { $terms = explode(‘,’, $request[‘terms’]); $taxonomy = $request[‘tax’];// Replace with your actual taxonomy name foreach ($terms as $term) { // Check if the term already exists $existing_term = term_exists($term, $taxonomy); // If the term doesn’t exist, create it if ($existing_term === 0 || $existing_term === null) { wp_insert_term($term, $taxonomy); } } }, 10, 2 );
Source: SoftEmblems
- Create Terms Using the Hook
Use the hook to create terms. The hook has a standard syntax followed by the name of the hook. The code for creating terms can be found in the WordPress Codex. - Add the Form to Your Page
Go back to your WordPress dashboard and add the form to your page using Elementor. Make sure to set the form to use Ajax and redirect to the current page after submission. - Test the Form
Test the form by adding new terms. You can add one or multiple terms at a time. - Extend the Functionality
If you want to add multiple taxonomies from the front-end, you can extend the functionality of the form by adding a select field that allows you to choose the taxonomy.
When You Should and Should Not Add This Functionality
The Ability to add WordPress Terms on the Front-end is a powerful feature, but it’s not always necessary or beneficial. Here are some scenarios where this technique can be particularly useful:
Add a Front-End form if…
- User-Generated Content
If your website relies heavily on user-generated content, allowing users to add terms from the front-end can streamline the content submission process. It gives users the ability to categorize their content accurately, making it easier for other users to find. - Multi-Author Platforms
On platforms with multiple authors, front-end term creation can help maintain a consistent categorization system. It allows authors to add new categories or tags that are relevant to their content, without needing access to the back-end. - Dynamic Content Sites
If your site’s content is constantly evolving, front-end term creation can help keep your taxonomy system up-to-date. For example, news sites or blogs covering a wide range of topics can benefit from this feature. - Community-Driven Sites
For community-driven sites like forums or social networks, allowing users to create terms from the front-end can foster more engaging and dynamic discussions. Users can create new topics or tags for their posts, encouraging more participation.
You should NOT Add a Front-End form if…
- Small or Personal Blogs
If you’re running a small blog or a personal website with a single author, front-end term creation might not be necessary. You likely have a clear structure for your content and can manage your taxonomy from the back-end without any issues. - Highly Structured Sites
For websites with a highly structured and specific taxonomy system, allowing front-end term creation could lead to inconsistency and confusion. It’s best to manage your terms from the back-end to maintain a clean and organized structure. - Sensitive or Regulated Content
If your website deals with sensitive or regulated content, you might want to avoid front-end term creation. This can prevent inappropriate or non-compliant terms from being added. - Lack of Moderation Resources
Front-end term creation can lead to a large number of new terms, which might require moderation to ensure relevance and appropriateness. If you don’t have the resources to moderate new terms, it might be best to stick to back-end term creation.
Remember, while this feature can be powerful, it’s important to use it responsibly. Allowing unchecked term creation can lead to a cluttered and confusing taxonomy system. Consider implementing moderation or approval processes to maintain a clean and effective taxonomy structure.
Common Issues
- Hook Not Working
If the hook is not working, make sure you have correctly inserted the action line in your function.php file. Also, check if the name of the hook in your form settings matches the one in your function.php file. - Form Not Redirecting
If the form is not redirecting to the current page after submission, make sure you have set the form to use Ajax and redirect to the current page in Elementor. - Cannot Add Multiple Terms
If you cannot add multiple terms at once, check if you have used the explode function correctly in your code to convert the text into an array.