Site logo

Archived topic

Sidebar Widgets to H3 on some pages

7 replies · Started by vodryy on September 12, 2018

Viewing posts 1–8 of 8

Hi,
I need help with change of Widgets H2 headings to H3, but I want to change to H3 only on homepage, categories, archives and tags pages. On single Pages and Posts leave H2.

I tried to use this following code to change it only on categories, but without success. It breaks all widget headings on all pages.

add_filter( 'generate_start_widget_title','generate_widget_title_h3' );
function generate_widget_title_h3()
{
if ( is_category() )
return '<h3 class="widget-title">';
}
add_filter( 'generate_end_widget_title','generate_widget_title_end_h3' );
function generate_widget_title_end_h3()
{
if ( is_category() )
return '</h3>';
}

Could you please help with that.

Jiri

Hi there,

Try this:

add_filter( 'generate_start_widget_title', function( $title ) {
    if ( is_category() ) {
        return '<h3 class="widget-title">';
    }

    return $title;
} );

add_filter( 'generate_end_widget_title', function( $title ) {
    if ( is_category() ) {
        return '</h3>';
    }

    return $title;
} );

Let me know :)

Hi Tom,
thank you for code. But it did not anything.
Widgets on all pages are with heading H2.
Tried this code with is_category and than separately with is_home.
Category pages and in the next try the home page are showing H2 as all other pages.
Tried to change variable $title to something else (to try if it is not coliding with other snippet).
Without success.

Best Regards

Jiri

Let's try this instead:

add_action( 'wp', function() {
    add_filter( 'generate_start_widget_title', function( $title ) {
        if ( is_category() ) {
            return '<h3 class="widget-title">';
        }

        return $title;
    } );

    add_filter( 'generate_end_widget_title', function( $title ) {
        if ( is_category() ) {
            return '</h3>';
        }

        return $title;
    } );
} );

Hi Tom,
It is still not changing widgets titles to H3.

Best Regards
Jiri

Can you link me to one of your category pages where it should be working?

Hi Tom,
I will try to rebuild my seo strategy.
Thank you very much for your effort.
Have a nice day

Jiri

You too :)

This archived topic is closed to new replies.