2

I have a custom taxonomy, 'genre.'

I'd like my editors, from the 'Edit Genre' screen (in the admin), to be able to link to the front end page for that genre/term.

So, at the top of the 'Edit Genre' page there would be a link such as:

See this page: mysite.com/genre/fiction

  • or - if I could have a 'Preview Changes' button, as in the Post Edit screen.

Possible?

Note, I've seen some solutions that suggest putting in a dummy custom meta box, using the description as the text/link. Is there a way to do the above without doing the meta box?

4

The dynamic hook {taxonomy}_term_edit_form_top can be used to output a link to the term's archive page.

Since we're dealing with terms under the genre taxonomy, we will attach our callback to the genre_term_edit_form_top hook.

/**
 * Adds a link to top of edit term form for terms under the
 * genre taxonomy.
 *
 * @param object $tag      Current taxonomy term object.
 * @param string $taxonomy Current $taxonomy slug.
 */
add_action( 'genre_term_edit_form_top', 'wpse_add_genre_link', 10, 2 );
function wpse_add_genre_link( $tag, $taxonomy ) {
  $term_link = get_term_link( $tag ) ; ?>

  <div class="term-link-container">
    <strong><?php _e( 'See this page:', 'text-domain' ); ?></strong>
    <a href="<?php echo esc_url( $term_link ) ?>"><?php echo esc_html( $term_link ); ?></a>
  <div><?php
}
  • 2
    Brilliant. Thank you. This is one of those less-known hooks with little written about it out in the web sphere. – Leora Deans Jul 31 '17 at 3:17
  • You got it, Leora! Don't hesitate to browse the source to look for goodies like this. Personally, I trend look at the source before searching the web. The inline docs are top notch. – Dave Romsey Jul 31 '17 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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