Support » Developing with WordPress » Widget title not displaying in WordPress version 5.8.2

  • ntdropper

    (@ntdropper)


    Hello, I am trying to build custom WordPress theme and when I added widget there is no title being displayed.
    Screen shot: https://ibb.co/cgbW8MR

    Widget code:
    function wphierarchy_widget_init() {
    register_sidebar( [
    ‘name’ => esc_html__( ‘Main Sidebar’, ‘wphierarchy’ ),
    ‘id’ => ‘main-sidebar’,
    ‘description’ => esc_html__( ‘Add widgets here.’, ‘wphierarchy’ ),
    ‘before_widget’ => ‘<section class=”widget”>’,
    ‘class’ => ‘custom-widget-area’,
    ‘after_widget’ => ‘</section>’,
    ‘before_title’ => ‘<h2 class=”widget-title”>’,
    ‘after_title’ => ‘</h2>’,
    ] );
    // Secondary widget for footer
    register_sidebar( [
    ‘name’ => esc_html__( ‘Footer Sidebar’, ‘wphierarchy’ ),
    ‘id’ => ‘footer-sidebar’,
    ‘description’ => esc_html__( ‘Add widgets here.’, ‘wphierarchy’ ),
    ‘before_widget’ => ‘<section class=”widget”>’,
    ‘class’ => ‘custom-widget-area’,
    ‘after_widget’ => ‘</section>’,
    ‘before_title’ => ‘<h2 class=”widget-title”>’,
    ‘after_title’ => ‘</h2>’,
    ] );
    }
    add_action(‘widgets_init’, ‘wphierarchy_widget_init’ );
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Is the code you use exactly like what’s posted here? All the quotes are the wrong kind, they are ‘curly’ instead of the required 'straight'.

    I’ve heard, but not confirmed, that the before/after title elements are only applied to “classic” widgets, block based widgets don’t use them. Could this be what your issue is?

    Thread Starter ntdropper

    (@ntdropper)

    Sorry did not get you.

    Moderator bcworkz

    (@bcworkz)

    Sorry, my bad, 2nd paragraph answers a question you didn’t ask.

    Anyway, once I corrected the quote issue in your code I get titles displayed when I tested your code. I used the legacy meta widget to test. Could the title be hidden by CSS per chance? Check the source HTML. Or the widget code could be at fault. Test with one of the default legacy widgets.

    Thread Starter ntdropper

    (@ntdropper)

    As I tried to use legacy widget. I dont have option to select the widget that I created. Please see images
    https://ibb.co/N9Q6RJ7

    Moderator bcworkz

    (@bcworkz)

    If you cannot select your widget in the customizer, there’s an issue with how you registered your widget. The code you’ve shared here only registers the sidebar/widget area for your theme, not the widget itself. If you see “Main Sidebar” and “Footer Sidebar” as places to put widgets (one level back from your screenshot), the code you posted code is working. But your widget areas will only appear in the customizer if the current page uses them. They should all appear regardless of where at Appearance > Widgets from the admin menu.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.