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?
1 Answer
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="https://wordpress.stackexchange.com/questions/275235/<?php echo esc_url( $term_link ) ?>"><?php echo esc_html( $term_link ); ?></a>
<div><?php
}