Support » Fixing WordPress » some Widget Title not linking css

  • Resolved auphoria


    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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • couldn’t you just add the <h2> in functions.php where your sidebar is registered?



    what do you mean?

    your sidebars get registered in functions.php like this:

    		'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



    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.

    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



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

    Cool, glad it worked!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘some Widget Title not linking css’ is closed to new replies.