admin管理员组

文章数量:1122832

In my theme I use <?php echo the_category(', '); ?> to get the categories, separates by comma, with links to them. But those links have no title attribute. Is there any way to get them?

In my theme I use <?php echo the_category(', '); ?> to get the categories, separates by comma, with links to them. But those links have no title attribute. Is there any way to get them?

Share Improve this question edited Nov 25, 2018 at 3:47 Damian asked Nov 25, 2018 at 3:41 DamianDamian 971 silver badge11 bronze badges 3
  • What do you need it for? A title attribute for a link that already has the same text is redundant, and it doesn't actually help accessibility or SEO. – Jacob Peattie Commented Nov 25, 2018 at 7:40
  • What should that title attr contain? – Krzysiek Dróżdż Commented Nov 25, 2018 at 8:39
  • I wanna reduce SEO title and alt errors... So alt and title could contain just name of the category. But now I think it's not worth of the work... – Damian Commented Nov 25, 2018 at 21:31
Add a comment  | 

1 Answer 1

Reset to default 0

There are no filters in get_the_category_list function, that will allow you to add title attribute to those links, so you'll have to write your own code for that...

<?php
    $categories = get_the_category();
    foreach ( $categories as $i => $cat ) :
        if ( $i ) echo ', ';
?>
    <a href="<?php echo esc_url( get_category_link( $category->term_id ) ); ?>" ><?php echo $category->name; ?></a>
<?php endforeach; ?>

本文标签: categoriesHow to get thecategory(3939) with link quottitlequot attribute