Title: Add taxonomy term code
Last modified: August 30, 2016

---

# Add taxonomy term code

 *  [kristina87](https://wordpress.org/support/users/kristina87/)
 * (@kristina87)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/add-taxonomy-term-code/)
 * Hi,
 * I found this code for adding a new term for a taxonomy from the front end.
 *     ```
       <?php
   
       // Check to see if correct form is being submitted, if so continue to process
       if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_term") {
   
           // Check to see if input field for new term is set
           if (isset ($_POST['term'])) {
   
               // If set, stores user input in variable
               $new_term =  $_POST['term'];
   
               // Function to handle inserting of new term into taxonomy
               wp_insert_term(
   
                 // The term (user input)
                 $new_term,
   
                 // The club taxonomy
                 'Club'        
   
               );
   
           } else { 
   
               // Else throw an error message
               echo 'Please enter a club name!';     
   
           }
   
       }
   
       ?>
   
       <form id="insert_term" name="insert_term" method="post" action=""> 
   
           <input type="text" value="" name="term" id="term" />
           <input type="submit" value="Add Club" id="submit" name="submit" />
           <input type="hidden" name="action" value="new_term" />
   
       </form>
       ```
   
 * I need help working this into a page. How can I insert both PHP & HTML?
 * Thanks in advance!

Viewing 1 replies (of 1 total)

 *  [Digico Paris](https://wordpress.org/support/users/digico-paris/)
 * (@digico-paris)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/add-taxonomy-term-code/#post-6812016)
 * Hello,
 * This code is clearly called from a button, or a search page, plus it can’t be
   used as copy and paste.
 * To work with taxonomy, you need to create some settings before calling anything
   like that (like in your theme functions.php). And quick answer is your term must
   be inside it – like animal term to call later dog or cat.
 * To learn more about how to mix php and html in same page, there are many tutorials
   over the net, and mainly the codex (codex.wordpress.org) where you have many 
   examples of how a theme is built, how to use taxonomies, so on.
 * Also for your question, WordPress often mixes php and html, but at different 
   levels. On a classic theme, low-level pages like header.php for a theme makes
   a lot of both but mainly html, functions.php is rather high-level with php only,
   and for instance a mid-level page called my-custom-page.php is in general 50%
   both.
 * Finally, mixing PHP and HTML is not an easy task at first glance, a good php 
   book is very useful for that too.

Viewing 1 replies (of 1 total)

The topic ‘Add taxonomy term code’ is closed to new replies.

## Tags

 * [custom taxonomy](https://wordpress.org/support/topic-tag/custom-taxonomy/)
 * [frontend](https://wordpress.org/support/topic-tag/frontend/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Digico Paris](https://wordpress.org/support/users/digico-paris/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/add-taxonomy-term-code/#post-6812016)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
