FEATURE Changing the default og image
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f12528f780
commit
0ebaf0d0bf
|
|
@ -331,17 +331,6 @@ function generate_og_meta_tags()
|
||||||
} elseif (is_single() || is_page()) {
|
} elseif (is_single() || is_page()) {
|
||||||
$og_title = get_the_title();
|
$og_title = get_the_title();
|
||||||
$og_description = get_the_excerpt();
|
$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)) {
|
if (empty($og_description)) {
|
||||||
$og_description = wp_trim_words(strip_tags(get_the_content()), 30);
|
$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 = str_replace(array("\r", "\n", "\t"), ' ', $og_description);
|
||||||
$og_description = wp_trim_words($og_description, 30);
|
$og_description = wp_trim_words($og_description, 30);
|
||||||
|
|
||||||
// Image
|
// Image Open Graph fixe
|
||||||
$og_image = '';
|
$og_image = get_template_directory_uri() . '/resources/img/og/dynamiques-og.png';
|
||||||
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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Type de contenu
|
// Type de contenu
|
||||||
$og_type = is_single() ? 'article' : 'website';
|
$og_type = is_single() ? 'article' : 'website';
|
||||||
|
|
@ -396,31 +364,9 @@ function generate_og_meta_tags()
|
||||||
|
|
||||||
// Auteur (pour les articles)
|
// Auteur (pour les articles)
|
||||||
$og_author = '';
|
$og_author = '';
|
||||||
$article_authors = array();
|
|
||||||
if (is_single()) {
|
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');
|
$og_author = get_the_author_meta('display_name');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Date de publication (pour les articles)
|
// Date de publication (pour les articles)
|
||||||
$published_time = '';
|
$published_time = '';
|
||||||
|
|
@ -457,22 +403,6 @@ function generate_og_meta_tags()
|
||||||
$meta_tags[] = '<meta property="article:modified_time" content="' . esc_attr($modified_time) . '" />';
|
$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
|
// Twitter Cards
|
||||||
$meta_tags[] = '<meta name="twitter:card" content="summary_large_image" />';
|
$meta_tags[] = '<meta name="twitter:card" content="summary_large_image" />';
|
||||||
$meta_tags[] = '<meta name="twitter:title" content="' . esc_attr($og_title) . '" />';
|
$meta_tags[] = '<meta name="twitter:title" content="' . esc_attr($og_title) . '" />';
|
||||||
|
|
|
||||||
BIN
resources/img/og/dynamiques-og.png
Normal file
BIN
resources/img/og/dynamiques-og.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 79 KiB |
Loading…
Reference in New Issue
Block a user