WordPress tip: How to make term edition easier

Simply paste this function on your functions.php file:

if ( !function_exists('edit_term_link') ) {
  function edit_term_link( $link = '', $before = '',
      $after = '', $term = null ) {

    if ( $term == null ) {
      global $wp_query;
      $term = $wp_query->get_queried_object();
    }

    $tax = get_taxonomy( $term->taxonomy );
    if ( !current_user_can($tax->cap->edit_terms) )
      return;

    if ( empty($link) )
      $link = __('Edit This');

    $link = '<a href="' . get_edit_tag_link( $term->term_id,
        $term->taxonomy ) . '" title="' . $link . '">' . $link . '</a>';
    echo $before .
       apply_filters( 'edit_term_link', $link, $term->term_id ) . $after;
  }
}

Once you saved your functions.php file, add the following code on any category, tag or taxonomy template:

<?php edit_term_link(); ?>

It will output a link (only if you’re logged in as an administrator, of course) to quickly edit the term.

Thanks to Joost de Valk for this great function!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

WordPress tip: How to make term edition easier

Leave a Reply

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