• Resolved markroth

    (@markroth)


    I want to change the widget-title from <h1 to <h3 in my SemPress child theme.

    I know I can do this in my child theme’s functions.php by changing the following code from the parent theme’s functions.php:

    function sempress_widgets_init() {
      register_sidebar( array(
        'name' => __( 'Sidebar 1', 'sempress' ),
        'id' => 'sidebar-1',
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget' => "</section>",
        'before_title' => '<h1 class="widget-title">',
        'after_title' => '</h1>',
      ) );
    
      register_sidebar( array(
        'name' => __( 'Sidebar 2', 'sempress' ),
        'id' => 'sidebar-2',
        'description' => __( 'An optional second sidebar area', 'sempress' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget' => "</section>",
        'before_title' => '<h1 class="widget-title">',
        'after_title' => '</h1>',
      ) );
    }
    add_action( 'init', 'sempress_widgets_init' );

    Despite a lot of research and some tries, I haven’t been able to get something workable. I gather I need to use remove_action somehow. But nothing I’ve read has penetrated this thick skull far enough to produce something usable.

    Could somebody please tell me exactly what my code needs to be?

    Thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi,

    You can just change the html markup on the two sidebars:
    So change this part of the code:

    'before_title' => '<h1 class="widget-title">',
       'after_title' => '</h1>',

    To

    'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',

    I hope this answers your question.
    The Best Of Luck

    Thread Starter markroth

    (@markroth)

    Thanks for the reply, mido116.

    Alas, that doesn’t do anything for the dynamic sidebars.

    That’s what I’m wanting to change.

    Well, I am not really sure what changes you are looking for on the sidebar, but that will change the widget tile from <h1>Tile</h1> to <h3>Title</h3>.
    You can inspect the widget title in your browser to if the change actually happened.
    maybe you are not seeing any changes because the tags h1 nad h3 has the same style in your theme.

    Thread Starter markroth

    (@markroth)

    The code in my opening post is what generates the dynamic sidebar.

    Your suggestion changes the static sidebar; it does nothing for the dynamic stuff.

    By the way, I noticed a few minutes ago over on github that pfefferle has in mind to change the SemPress sidebar header tags to <h3> in version 1.4.5, so that’s great!

    But for the sake of understanding WP and php a little better, I’d still like to know how to code up a child theme’s functions.php as I asked in my opening post.

    And thanks again, mido, for engaging my inquiry!

    If you take a look at the line 269 on pfefferle’s code you’ll see that he did exactly what i said, he changed h1 to h3. But still I am not really sure what you mean by static and dynamic sidebar.
    And as for knowing how to code up a child theme’s functions.php you can refer to it here where they explain exactly how you can create your own functions.php on your child theme.

    The best of Luck

    Thread Starter markroth

    (@markroth)

    I’m sorry, mido116. I thought you were telling me in your first comment that I should make those changes in sidebar.php. My apologies for misunderstanding.

    So, now that I’m on the same page with you, yes, I know that’s what needs to change. But like I said in my opening post, I just can’t get how to implement remove_action (or whatever it takes in the child theme).

    You gave me a link in the Codex, but I’d already been there repeatedly. And I’ve read plenty of other stuff. Like I said in my opening, “nothing I’ve read has penetrated this thick skull far enough to produce something usable.” 🙁

    Thread Starter markroth

    (@markroth)

    OK, I think I got it now (through more trial and error):

    // CHANGES WIDGET HEADINGS TO H3 (INSTEAD OF H1)
    
    add_action( 'after_setup_theme', 'remove_parent_theme_features', 10 );
    
    function remove_parent_theme_features() {
    	remove_action( 'init', 'sempress_widgets_init' );
    	add_action( 'init', 'ph_sempress_widgets_init' );
    }
    
    function ph_sempress_widgets_init() {
      register_sidebar( array(
        'name' => __( 'Sidebar 1', 'sempress' ),
        'id' => 'sidebar-1',
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget' => "</section>",
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
      ) );
    
      register_sidebar( array(
        'name' => __( 'Sidebar 2', 'sempress' ),
        'id' => 'sidebar-2',
        'description' => __( 'An optional second sidebar area', 'sempress' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget' => "</section>",
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
      ) );
    }

    It works for me. Is it proper coding, though?

    Here’s where I have it implemented: Panting Hart.

    Yes it is clean code, I can see that you removed the action of the parent theme and replaced it with your action. Personally I would do it like that.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Changing widgets in functions.php’ is closed to new replies.