
Intermédiaire
Partager la publication "Ajouter Hashtag à une étiquette"
Tags WordPress avec un Hashtag : Nous allons dans ce tutoriel nous donner la possibilité d’ajouter un hashtag dans nos tags WordPress. Le principe est d’abord de vérifier une condition pour nos tags :
Donc on demande dans notre fonction WordPress de vérifier que on n’a bien des tags avec un if :
1 2 | if( $tags = get_the_tags() ) { } |
Puis ensuite on fait un beau foreach en disant pour chaque tag dans l’ensemble des tags nous allons changer son comportement (Disons son HTML).
Dans notre HTML, nous y ajoutons notre hashtag.
1 2 3 4 | foreach( $tags as $tag ) { $sep = ( $tag === end( $tags ) ) ? '' : ', '; echo '<a href="' . get_term_link( $tag, $tag->taxonomy ) . '">#' . $tag->name . '</a>' . $sep; } |
Tags WordPress avec un Hashtag : Le code final
1 2 3 4 5 6 7 8 9 10 | ///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////// Hashtags Mots Clés ////////////////////////////////////////// function themepresstags() { if( $tags = get_the_tags() ) { foreach( $tags as $tag ) { $sep = ( $tag === end( $tags ) ) ? '' : ', '; echo '<a href="' . get_term_link( $tag, $tag->taxonomy ) . '">#' . $tag->name . '</a>' . $sep; } } } |