Hello Guys Im trying to put a search box in my menubar and I was able to do it BUT how can I use the woocommerce search product instead??
heres my current Code in the function.php:
add_filter( 'wp_nav_menu_items','add_search_box', 10, 2 );
function add_search_box( $items, $args ) {
$items .= '<li>' . get_search_form( false ) . '</li>';
return $items;
}
I want to put Woocommerce_product_search in my MENUBAR anybody can help me.
SOrry for the ENglish im really not good in it.
Register a Sidebar in your Functions.php and then add the sidebar into your container where you want the search box to appear. Then add the Woocommerce Search Widget to this sidebar inside the Wordpress Admin interface.
Add this to Functions.php:
register_sidebar(array(
'id' => 'search-widget',
'name' => __('Search Widget'),
'description' => __('Drag search widget to this container'),
'before_widget' => '<article id="%1$s" class="widget %2$s">',
'after_widget' => '</article>',
'before_title' => '<h6>',
'after_title' => '</h6>'
));
}
Add this to your Header.php or whichever file contains the code where the search box needs to go:
<?php dynamic_sidebar("search-widget"); ?>
Related
I want to display default Woo-commerce product filter in my custom plugin development. I have used following short-code for display products.
echo do_shortcode("[products]");
It's working and product also showing but i also want to display default product filter in Woo-commerce , I used following short-code but default product filter is not showing.
[woocommerce_product_filter_products]
[woocommerce_product_filter]
Is there another way to display default product filter in plugin development or another pages?
Register a Sidebar:
if ( function_exists('shortcodeWidget') )
register_sidebar(array(
'name' => 'Shortode widget for filter',
'id' => 'shortcode-widget',
'before_widget' => '<div class = "filterWidget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
)
);
After register the shortcode
function shortcodeSidebar(){
ob_start();
get_sidebar('shortcode-widget');
$sidebar= ob_get_contents();
ob_end_clean();
return $sidebar;
}
add_shortcode('filterWoocommerce', 'shortcodeSidebar');
And then add the filter in the custom widget.
So, I'm making my own theme from scratch for Wordpress with the Woocommerce plugin. I can seem to find how to add a sidebar widget to my Shop page... There is no area for it in thw Widgets menu and I can't seem to find how to create it and edit it...
Can someone help me understant how to create it and which files/code do I need to create in my child theme?
You need to create a widget area in your functions.php with this function :
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Sidebar',
'before_widget' => '<div class = "widget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
)
);
And for display in your theme :
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Sidebar") ) : ?>
Try this on header.php for example, you can add sidebar where u want
if ( is_active_sidebar( 'Sidebar' ) ) {
dynamic_sidebar( 'Sidebar' );
}
I'm going through a client's site using Siteimprove's chrome extension to test for compliance. I'm getting a "Landmarks with identical names" error on two asides in one sidebar area. In the register sidebar code in functions.php, I have:
'before_widget' => '<aside id="%1$s" class="widget %2$s" aria-label="Job Openings and Events">',
This is working and assigning the label, but there are two widgets in this sidebar (a text widget and events list widget) and Wordpress is creating an aside for each with the same label. Is there some sort of nth assignment or something I can do to assign each aside in this sidebar with a different label to prevent redundancy?
See this example,
function my_edit_widget_func($params) {
$params[0]['before_widget'] = '<aside id="%1$s" class="widget %2$s" aria-label="' . $params[0]['widget_name'] . '">' ;
return $params;
}
add_filter('dynamic_sidebar_params', 'my_edit_widget_func');
Hope this will helps you. For more information please visit.
dynamic_sidebar Function to Generate Class
Add class to specific widget in WordPress
Wordpress : Change title of sidebar widget dynamically
Ask
register_sidebar(array(
'name' => 'Footer #2',
'id' => 'footer2',
'description' => 'Footer widget 2',
'before_widget' => '<aside role="complementary" id="%1$s" class="widget-content footer-widget" aria-label="[title]">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title footer-widget-title">',
'after_title' => '</h2>' ,
));
function stp_accessibility_widget_func($params) {
$name = isset($params[0]['widget_name']) ? $params[0]['widget_name'] : "";
$params[0]['before_widget'] = str_replace('[title]', esc_attr($name), $params[0]['before_widget'] );
return $params;
}
add_filter('dynamic_sidebar_params', 'stp_accessibility_widget_func');
Use this solution it will add aria-label in all the widgets
I'm creating a custom WordPress template which has 4 "sidebars" one for the header, a separate sidebar for the left and right columns, and then another sidebar for the footer, all that's fine and working properly. However, with my template, the header sidebar can only hold one widget at a time, so I was wondering if there was a way to add multiple widgets to the sidebar, but manipulate the code somehow to only display a random (or even in some specific order) widget at a time, which will change on each new page reload.
Code I used to make the sidebar:
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Header Sidebar Widgets',
'id' => 'sidebar-widgets-header',
'description' => 'The Header Can Only Support One (1) Widget.',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
}
And then the code I used to add the sidebar to my template:
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-widgets-header') ) :
endif;
Here is an image of the sidebar within my admin currently:
(source: illstudios.com)
Quote One and Featured Videos are custom widgets I created. So is there a way to only choose one random widget from the selection and only display one widget at a time?
There's a filter that returns all widgets in all sidebars. We can shuffle and trim one of the sidebars with it:
if( !is_admin() )
{
add_filter( 'sidebars_widgets', 'sidebar_so_23691473' );
}
function sidebar_so_23691473( $sidebars_widgets )
{
shuffle( $sidebars_widgets['sidebar-widgets-header'] );
$only_one = array_slice( $sidebars_widgets['sidebar-widgets-header'] , -1 );
$sidebars_widgets['sidebar-widgets-header'] = $only_one;
return $sidebars_widgets;
}
I am new to wordpress. I use the code below to display secondary widgets. This code shows all recent posts in the sidebar but I want a secondary widget for a specific category.
<?php dynamic_sidebar( 'secondary-widget-area' ); ?>
You have to register/declare your widgetized area before you can use it. This happens in the functions.php, so that your theme is aware of the widget area.
<?php
/**
* Register our sidebars and widgetized areas.
*
*/
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'Home right sidebar',
'id' => 'home_right_1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
?>
If you're just trying to add a secondary widget to an existing widgetized area, then no coding is needed. Just go to Appearance>Widgets and drag and drop HTML blocks or other custom widgets to the appropriate area.
More on Using Widgets
More on Widgetizing