WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] some Widget Title not linking css (8 posts)

  1. auphoria
    Member
    Posted 3 years ago #

    The theme I'm using has widget titles in <div></div> instead of <h2></h2>. So, my sidebar#h2 css wasn't linking.

    I used this code in functions.php

    function my_widget_title($title){
      return '<h2>' . $title . '</h2>';
    }
    add_filter('widget_title', 'my_widget_title');

    it worked really well for 2 of my widget titles, but the rest are still in plain text. Does anyone know why?

    p.s. I tried doing <h3> with the same code again, but doesn't work.

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    couldn't you just add the <h2> in functions.php where your sidebar is registered?

  3. auphoria
    Member
    Posted 3 years ago #

    what do you mean?

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    your sidebars get registered in functions.php like this:

    register_sidebar(array(
    		'id' => 'primary',
    		'name' => __('Main Sidebar'),
    		'description' => __('Sidebar used on most pages'),
    		'before_widget' => '<li class="widget %2$s" id="%1$s">'. "\n\t\t\t" .'<div class="rounded">'. "\n\t\t\t\t",
    		'after_widget' => "\t" . '</div>' ."\n\t\t". '</li>' . "\n",
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>' . "\n\t"
    	));

    the before title and after title control what html tags appear before and after the title

    Also, are these widgets yo added, or default ones that came with the theme? the above controls widgets you add in the widget menu, default widgets are coded in sidebar.php

  5. auphoria
    Member
    Posted 3 years ago #

    do I just copy paste this code into functions.php? I tried that and changed it to h2, nothing happens.

    these are the widgets I added myself.

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    no.... don't add that to functions.php, you should already have code like that in there. Something that mentions register_sidebar

    You need to edit what you already have.... But you wouldn't want to replace the <div> with <h2> you would want to add..... otherwise it could screw up your layout

  7. auphoria
    Member
    Posted 3 years ago #

    omg I'm so blind, thank you so much!!! It's fixed. Thank You!!!!

  8. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    Cool, glad it worked!

Topic Closed

This topic has been closed to new replies.

About this Topic