3

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?

1 Answer 1

5

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 );
});
1
  • 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. Commented Jul 23, 2020 at 2:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.