Right way to add HTML bloginfo name using a filter

You can’t check the context while the filter callback is called, because the element is already in the frontend. There are 3 solutions though:

1. jQuery

Search for the element and add html to the places in the name.

2. PHP in element

Get the bloginfo(‘name’); in the element and change it on that place using PHP.

3. PHP in header

Add HTML to your bloginfo(‘name’) and strip it back out in de header.php file where the title is generated using the strip_tags() function:

strip_tags(get_bloginfo('name'));

I’d go with the 3rd option, since it’s the fastest method without changing to much.