Site logo

Archived topic

Add WIDGET inside ELEMENT

2 replies · Started by Francisco on March 8, 2023

Viewing posts 1–3 of 3

Hi, I need to create a ELEMENT that will be placed inside some pages (in APPAREANCE -> ELEMENTS) . Inside that ELEMENT I need to add a WIDGET. Is that possible?

I have also tried creating this

function woo_custom_sidebar() {
register_sidebar(array(
'name' => 'Widget para Buscador de Vehiculos',
'id' => 'wooshopwidget',
'description' => 'Widget para Buscador de Vehiculos',
'before_widget' => '

',
'after_widget' => '

',
'before_title' => '<h3>',
'after_title' => '</h3>',
)
);
}
add_action( 'widgets_init', 'woo_custom_sidebar' );

And then inserted this CODE inside the ELEMENT:

<?php if(!dynamic_sidebar('wooshopwidget')) ; ?>

But it doesnt work.

Thanks
Francisco

Hi Francisco,

What's the widget you want to add?

Does the widget have a block version? If so, you can add the block to the block element.

Let me know!

I have finally added like this

function my_zone_widgets() {
    register_sidebar( array(
        'name' => __( 'My Widgets Area', 'mi-tema' ),
        'id' => 'my_widgets_area',
        'description' => __( 'Esta es mi zona de widgets personalizada', 'mi-tema' ),
        'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h2 class="widget-title">',
        'after_title' => '</h2>',
    ) );
}
add_action( 'widgets_init', 'my_zone_widgets' );

add_action( 'woocommerce_archive_description', 'my_function_widget', 10 );
function my_function_widget() {
    if ( is_shop() ) {
        echo '<div class="nueva-area-de-widgets content-area" style="width: 100% !important;text-align: center !important;padding:20px;margin-bottom: 20px;border-radius: 25px;">';
        dynamic_sidebar( 'my_widgets_area' );
        echo '</div>';
    }
}
This archived topic is closed to new replies.