Site logo

Archived topic

Change logo of articles inside category

7 replies · Started by Mathias on February 4, 2022

Viewing posts 1–8 of 8

Hello,

I managed to change the logo of my website for a specific category thanks to the following documentation : https://docs.generatepress.com/article/generate_logo/#example.

It's working well for category archive.

But I would like all the articles inside this category to have this specific logo too.

It would be easier if every new article in this category automatically had the specific logo.

I tried to do it with is_category( ) but it's not working (The logo appears on the whole site.).

Thanks in advance for your help!

Kind regards.

Thanks!

in_category() is what I tried (and not is_category( ), sorry).

Here's the code I tried. It change the logo, but on the entire site and not only in a specific category as I need.

add_filter( 'generate_logo', function( $logo ) {
      // Return our category logo URL
    if ( in_category('category') ) {
        return 'URL';
    }

    // Otherwise, return our default logo
    return $logo; 
 } );

I don't know anything about PHP, I'm probably wrong.

How many different logo snippets are you using ?

For the moment I'm trying with 2 different ones (1 for the home and one for a category and its articles).

In total there will be 4.

Instead of many snippets - Try one snippet to set the various logo choices - for example :

add_filter( 'generate_logo', function( $logo ) {

    if ( in_category('category') ) {
        $logo = 'URL';
    }
    if ( is_category('category') ) {
        $logo = 'URL';
    }

    return $logo; 
 } );

It's working.

Thanks a lot for your time and help.

Glad to hear that!

This archived topic is closed to new replies.