Currently I'm styling as project where I need to add a custom CSS to the_author_posts_link().

I want to add the class "blog-link" with the the_author_posts_link() . How do I add a css class to it?


You can use the the_author_posts_link filter to add the custom blog-link class:

 * Add the 'blog-link' class to the output of the_author_posts_link()
add_filter( 'the_author_posts_link', function( $link )
    return str_replace( 'rel="author"', 'rel="author" class="blog-link"', $link );
  • Just be careful doing something like this because if another plugin or the theme has already done something similar you will end up with 2 class attributes. I would recommend using strpos to first check if class=" exists and if so insert your classname there.
    – WPExplorer
    Jul 23 '20 at 2:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.