Site logo

Archived topic

Adding additional classes to site logo

7 replies · Started by Dalibor on July 18, 2022

Viewing posts 1–8 of 8

I've built a site header with elements->global header. As I'm trying to animate the logo which is a part of it, I'd like to add additional classes to the .site-logo class.
As it's not part of the page builder, I can't just add additional classes to the container.
Help?

No, I've done it through Appearance/Customize/Site identity, and as I'm using the Global header within the Elements, I don't see a site logo block.
https://prnt.sc/b3aLu112E7Rm

Oh you mean header element.. I misunderstood your question.

If the logo is added using customizer > site identity, the .site-logo class should be there by default.

I'm aware of that, I'm trying to animate the logo, so I'll need to append additional (custom) classes to it.
Is there a way to do it, when I can't add additional classes through a page builder?

Hi Dalibor,

We can use a filter to do as such. Here’s a PHP snippet you may try:

add_filter( 'generate_logo_output', function( $output, $logo_url, $html ){
	$my_search='site-logo';
	$my_new_class='ADD-CLASS-NAME-HERE';
	$my_replace= $my_search . ' ' . $my_new_class;
	$new_content = str_replace($my_search, $my_replace, $output);
	return $new_content;
} , 10, 3 );

Replace ADD-CLASS-NAME-HERE with your class to add. This will append your new class after site-logo class.

Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets

Hope this helps!

Thank you, Fernando, that worked perfectly!

You’re welcome Dalibor!

This archived topic is closed to new replies.