add canonical authors

This commit is contained in:
argoexpert press
2025-04-22 22:54:20 +03:00
parent 3d8a4a5054
commit 1c4b27d358
6 changed files with 26 additions and 7 deletions

View File

@@ -639,9 +639,9 @@ function custom_meta_tags() {
$term = get_queried_object();
$canonical_url = get_term_link($term);
if ($paged > 1) {
//if ($paged > 1) {
$meta_tags .= '<link rel="canonical" href="' . esc_url($canonical_url) . '" />' . PHP_EOL;
}
// }
$title = $term->name . ' - ' . $sitename;
$description = !empty(trim($term->description)) ? $term->description : $term->name;
@@ -657,6 +657,25 @@ function custom_meta_tags() {
$og_tags .= '<meta property="og:title" content="' . esc_html($title) . '" />' . PHP_EOL;
$og_tags .= '<meta property="og:description" content="' . esc_attr($description) . '" />' . PHP_EOL;
} elseif (is_author()) {
$author = get_queried_object();
$author_name = $author->display_name;
$author_description = get_the_author_meta('description', $author->ID);
$canonical_url = get_author_posts_url($author->ID);
$title = 'Материалы автора ' . $author_name . ' - ' . $sitename;
$description = !empty($author_description) ? $author_description : 'Материалы, опубликованные автором ' . $author_name;
$meta_tags .= '<title>' . esc_html($title) . '</title>' . PHP_EOL;
$meta_tags .= '<meta name="description" content="' . esc_attr($description) . '">' . PHP_EOL;
$meta_tags .= '<meta name="author" content="' . esc_attr($author_name) . '">' . PHP_EOL;
$meta_tags .= '<link rel="canonical" href="' . esc_url($canonical_url) . '" />' . PHP_EOL;
$og_tags .= '<meta property="og:url" content="' . esc_url($canonical_url) . '" />' . PHP_EOL;
$og_tags .= '<meta property="og:title" content="' . esc_html($title) . '" />' . PHP_EOL;
$og_tags .= '<meta property="og:description" content="' . esc_attr($description) . '" />' . PHP_EOL;
} elseif (is_single() || is_page()) {
$post = get_queried_object();