• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Isocèle Web Design

Isocèle Web Design

Création de sites Web

  • Réalisations
  • DEVIS
  • Contact

Afficher une taxonomie personnalisée via un shortcode

Astuce pour WordPress avec le Framework Genesis.

Après avoir créé un type d’articles personnalisé (Custom Post Type) “Fleurs” et sa taxonomie spécifique “Couleur” (Custom Taxonomy), j’utilise le plugin Featured Custom Post Types for Genesis pour construire ma page d’accueil avec Gutenberg.

J’ai besoin d’afficher ma taxonomie dans le “Show Post Info” où normalement on peut afficher les catégories via un shortcode.

Pour cela je vais ajouter une fonction dans mon fichier functions.php dans le dossier de mon Thème Enfant (Child Theme).

add_shortcode( 'couleur', 'category_in_content' );
function category_in_content($atts){
    global $post;
    $html  = '';
    $taxonomy = 'couleur';
    $terms = get_the_terms( $post, $taxonomy );

    if ( !empty( $terms ) ) {
        foreach ($terms as $term) {
            $html .= '<a href="' . get_term_link( $term, $taxonomy ) . '">' . $term->name . '</a>';
        }
    }

    return $html;
}

Ensuite il suffit d’ajouter dans le Plugin Featured Custom Post Types et dans le champ “Show Post Info” le shortcode :

[couleur]

On peut aussi l’ajouter dans Personnalisation>Theme Settings>SingularContent>EntryMeta


Primary Sidebar

  • Tutoriels
  • Les bases
  • Avancé

archive bases champ personnalise child theme css custom field genesis gratuit headroom hebergement indispensable js php plugin plugins positionnement script SEO shortcode taxonomie technique theme tutoriel Wordpress

Footer


Politique de confidentialité

Isocèle Web Design
Rennes
France
contact(at)isocele-webdesign.fr

Font Basteleur by Keussel. Distributed by velvetyne.fr