FEATURE Changing the default og image
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Nonimart 2025-09-17 15:16:34 +02:00
parent f12528f780
commit 0ebaf0d0bf
2 changed files with 3 additions and 73 deletions

View File

@ -331,17 +331,6 @@ function generate_og_meta_tags()
} elseif (is_single() || is_page()) {
$og_title = get_the_title();
$og_description = get_the_excerpt();
// Pour les articles, améliorer la description avec les métadonnées
if (empty($og_description) && get_post_type() === 'articles') {
// Essayer d'utiliser le champ de référence de citation si disponible
$cite_reference = get_field('cite_reference');
if (!empty($cite_reference)) {
$og_description = strip_tags($cite_reference);
}
}
// Fallback vers le contenu si toujours vide
if (empty($og_description)) {
$og_description = wp_trim_words(strip_tags(get_the_content()), 30);
}
@ -364,29 +353,8 @@ function generate_og_meta_tags()
$og_description = str_replace(array("\r", "\n", "\t"), ' ', $og_description);
$og_description = wp_trim_words($og_description, 30);
// Image
$og_image = '';
if (is_single() || is_page()) {
if (has_post_thumbnail()) {
$og_image = get_the_post_thumbnail_url(null, 'large');
}
}
// Image par défaut si aucune image n'est trouvée
if (empty($og_image)) {
// Essayer d'utiliser le logo personnalisé du site
$custom_logo = wp_get_attachment_image_src(get_theme_mod('custom_logo'), 'large');
if ($custom_logo) {
$og_image = $custom_logo[0];
} else {
// Utiliser l'icône du site
$og_image = get_site_icon_url(512);
// Si pas d'icône de site, utiliser une image par défaut du thème
if (empty($og_image)) {
$og_image = get_template_directory_uri() . '/resources/img/covers/carhop-articles-page-cover.svg';
}
}
}
// Image Open Graph fixe
$og_image = get_template_directory_uri() . '/resources/img/og/dynamiques-og.png';
// Type de contenu
$og_type = is_single() ? 'article' : 'website';
@ -396,31 +364,9 @@ function generate_og_meta_tags()
// Auteur (pour les articles)
$og_author = '';
$article_authors = array();
if (is_single()) {
$post_type = get_post_type();
if ($post_type === 'articles') {
// Pour les articles, utiliser le champ ACF 'authors'
$authors = get_field('authors');
if ($authors && is_array($authors)) {
foreach ($authors as $author) {
$first_name = get_field('first_name', $author->ID) ?: '';
$last_name = get_field('last_name', $author->ID) ?: '';
$author_name = trim($first_name . ' ' . $last_name);
if (empty($author_name)) {
$author_name = $author->post_title;
}
$article_authors[] = $author_name;
}
$og_author = implode(', ', $article_authors);
}
}
// Fallback vers l'auteur WordPress standard
if (empty($og_author)) {
$og_author = get_the_author_meta('display_name');
}
}
// Date de publication (pour les articles)
$published_time = '';
@ -457,22 +403,6 @@ function generate_og_meta_tags()
$meta_tags[] = '<meta property="article:modified_time" content="' . esc_attr($modified_time) . '" />';
}
// Ajouter les tags/sections pour les articles
if (is_single() && get_post_type() === 'articles') {
$article_tags = get_the_tags();
if ($article_tags) {
foreach ($article_tags as $tag) {
$meta_tags[] = '<meta property="article:tag" content="' . esc_attr($tag->name) . '" />';
}
}
// Ajouter la section/revue si disponible
$related_revue = get_field('related_revue');
if ($related_revue) {
$meta_tags[] = '<meta property="article:section" content="' . esc_attr($related_revue->post_title) . '" />';
}
}
// Twitter Cards
$meta_tags[] = '<meta name="twitter:card" content="summary_large_image" />';
$meta_tags[] = '<meta name="twitter:title" content="' . esc_attr($og_title) . '" />';

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB