1

I'm trying to get a wrapper around my h3 widget title, because i want to give the h3 a vertical align bottom. Currently i'm registering my widget as following:

function usp_widgets_init(){
    if (function_exists('register_sidebar')) {
        register_sidebar(array(
            'name' => 'Front page widgets',
            'id' => 'widgets-front',
            'description' => 'Geschikt voor de USPs',
            'before_widget' => '<div class="skill hidden">',
            'after_widget' => '</div>',
            'before_title' => '<div class="widget-title"><h3>',
            'after_title' => '</h3></div>'
        ));
    }
} add_action( 'widgets_init', 'usp_widgets_init' );

Now the title will get the h3 tags, but it isn't wrapped by the div. Does anyone know how to fix this? Btw, i can't use display:table-cell for vertical aligning.

Current output:

<h3>Widget Title</h3>

Wished output:

<div class='widget-title'><h3>Widget Title</h3></div>

Thanks in advance!

3
  • I see I accidentally added an extra quote (") after widget-title, but this happened with copy-pasting. This is not in my source code so it's not the problem. – Thom Apr 25 '17 at 18:26
  • Are you looking at the raw source of your page or an inspector view? What happens if you remove your if statement? – jdm2112 Apr 25 '17 at 18:52
  • Your code looks fine to me, except that the conditional is not necessary. Might be some sort of caching problem. – cjbj Apr 25 '17 at 18:57
0

I think you missed , at the of after_title that's why it's not working. Use this code it's working fine.

register_sidebar( array(
        'name'          => 'Custom code widget',
        'id'            => 'custom-code',
        'description'   => 'Cutom code for all pages.',
        'before_widget' => '<div class="custom-description">',
        'after_widget'  => '</div>',
        'before_title'  => '<div class="custom-code-title"><h2 class="widget-title">',
        'after_title'   => '</h2></div>',
    ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.