Les Twitter Cards peuvent être utilisées pour vraiment renforcer votre présence sur Twitter. Pour ajouter automatiquement une Twitter Card à chacun de vos articles, copiez et collez cette portion de code dans le fichier functions.php de votre thème:
function add_twitter_cards() { if(is_single()) { $tc_url = get_permalink(); $tc_title = get_the_title(); $tc_description = get_the_excerpt(); $tc_image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full ); $tc_image_thumb = $tc_image[0]; $tc_author = str_replace('@', '', get_the_author_meta('twitter')); ?> <meta name="twitter:card" value="summary" /> <meta name="twitter:site" value="@elegantthemes" /> <meta name="twitter:title" value="<?php echo $tc_title; ?>" /> <meta name="twitter:description" value="<?php echo $tc_description; ?>" /> <meta name="twitter:url" value="<?php echo $tc_url; ?>" /> <?php if($tc_image) { ?> <meta name="twitter:image" value="<?php echo $tc_image_thumb; ?>" /> <?php } if($tc_author) { ?> <meta name="twitter:creator" value="@<?php echo $tc_author; ?>" /> <? } } }
Et voilà!