I have a footer widget that has a Navigation Menu block. I want the wrapper div for the ul to be a nav tag. How can i do this? I tried it with the 'wp_nav_menu_args' hook, but it doesn't work. Although for a header menu made with wp_nav_menu it works.
register_sidebar(array(
'name' => 'Footer Widget Area',
'id' => 'footer-widget',
'description' => 'Footer Widget for blocks',
'before_widget' => '<div class="footer-content__widget">',
'after_widget' => '</div>',
));
function my_nav_menu_args($args = '') {
if ('footer' == $args['theme_location']) {
if ($args['container'] == 'div') {
$args['container'] = 'nav';
}
}
return $args;
}
add_filter('wp_nav_menu_args', 'my_nav_menu_args');
Related
I'm trying to display a custom sidebar in a page. The code works with custom post types "news" posts but wont work with the page "na-midia". In the page the defaul sidebar is shown.
// Custom Sidebar
function prefix_custom_sidebar() {
register_sidebar( array(
'name' => __( 'Custom Sidebar MÃdia', 'page-builder-framework' ),
'id' => 'custom-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="wpbf-widgettitle">',
'after_title' => '</h4>'
) );
}
add_action( 'widgets_init', 'prefix_custom_sidebar' );
// Replace the default sidebar with our new custom sidebar on all docs posts
function prefix_do_custom_sidebar( $sidebar ) {
// this statement works for custom post types
if( is_singular( 'news' ) ) {
$sidebar ='custom-sidebar';
}
// this statement NOT works for the page which is displaying the posts, display the default sidebar instead
elseif ( is_singular( 'na-midia' ) ) {
$sidebar ='custom-sidebar';
}
return $sidebar;
}
add_filter( 'wpbf_do_sidebar', 'prefix_do_custom_sidebar' );
Solved!
elseif ( is_page ( 'na-midia' ) ) {
$sidebar ='custom-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 want to remove main sidebar from dwqa-question page and want to add custom sidebar in that page.
I wrote a code for it in functions.php :
function dwqa_theme_register_sidebar() {
register_sidebar( array(
'name' => __( 'Single Question', 'multinews' ),
'id' => 'dqwa',
'class' => '',
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'dwqa_theme_register_sidebar' );
function remove_main_sidebar_dwqa_question(){
if ( is_singular('dwqa-question') ){
unregister_sidebar( 'Main Sidebar' );
}
}
add_action( 'widget_init', 'remove_main_sidebar_dwqa_question' );
And this code in page.php :
<?php if ( is_singular('dwqa-question') ): ?>
<?php dynamic_sidebar('dqwa') ?>
<?php endif; ?>
Below is the output screenshot :
single question page
I think you dont need to de-register the main sidebar every time, it will take time to render the output. Just write the code in siderbar.php. Here I am mixing some of your code with.
<?php
if ( is_singular('dwqa-question') )
{
dynamic_sidebar('dqwa');
}
else
{
/** FOR OTHER THAN DWQA ***/
dynamic_sidebar('main-sidebar'); //I might be wrong on ID
}//end if
?>
Hope it will work for you
I'm trying to create a simple nav in wordpress, however the wp_nav_menu parameters are ignored , am I missing something obvious?
I'm using a blank template called html5 blank. The Steps i've taken so are listed below
1) Register the menu in functions.php
2) From word press back end Create a menu called 'p' and assign pages
3) Give the menu a theme location
Registering and assigning menu location work fine , some but for some reason the wp_ parameters are ignored EG container , menu class, menu id etc...
If i inspect element, the container 'nav' is missing and the li items have default word press classes
BELOW is my code
Code in header.php
<?php html5blank_nav() ?>
Code in functions.php
function html5blank_nav()
{
wp_nav_menu(
array(
'theme_location' => 'primary pete',
'menu' => 'p'
'container' => 'nav',
'container_class' => '',
'container_id' => '',
'menu_class' => 'slimmenu',
'menu_id' => 'navigation',
'echo' => true,
'fallback_cb' => 'false',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul>%3$s</ul>',
'depth' => 0,
'walker' => ''
)
);
}
// Register HTML5 Blank Navigation
function register_html5_menu()
{
register_nav_menus(array( // Using array to specify more menus if needed
'primary' => __('primary pete', 'Primary Menu'),
'sidebar-menu' => __('Sidebar Menu', 'html5blank'),
'extra-menu' => __('Extra Menu', 'html5blank')
));
}
// Remove the <div> surrounding the dynamic navigation to cleanup markup
function my_wp_nav_menu_args($args = '')
{
$args['container'] = false;
return $args;
}
// Remove Injected classes, ID's and Page ID's from Navigation <li> items
function my_css_attributes_filter($var)
{
return is_array($var) ? array() : '';
}
// Remove invalid rel attribute values in the categorylist
function remove_category_rel_from_category_list($thelist)
{
return str_replace('rel="category tag"', 'rel="tag"', $thelist);
}
// Add page slug to body class, love this - Credit: Starkers Wordpress Theme
function add_slug_to_body_class($classes)
{
global $post;
if (is_home()) {
$key = array_search('blog', $classes);
if ($key > -1) {
unset($classes[$key]);
}
} elseif (is_page()) {
$classes[] = sanitize_html_class($post->post_name);
} elseif (is_singular()) {
$classes[] = sanitize_html_class($post->post_name);
}
return $classes;
}
Many thanks,
P
When i try to reproduce this the menu with container_class => 'slimmenu' is shown.
Are you sure when you add a class to the container_class parameter this is not shown in the inspector?
Also noticed a missing comma after the parameter 'p' when i copied your code. But i don't think it will resolve your problem.
I would like to create a one-page wordpress website, where the navigation/menu points to different sections of the website. I would like to wrap my new Contact Form Widget in a section where the menu item "Contact" could point to. As seen in the code, I already have a 'before' div around the widget of "div class="contact-form-widget-wrapper". I can technically turn that into a section, however I would like to have more than one widget per section. Would anybody be able to help on how to wrap the widget/s in a section?
I'm using the Genesis Child Theme, which I'm trying to customize.
/* Contact Form Widget***************/
function contact_form_widget() {
register_sidebar( array(
'name' => __( 'Contact Form', 'genesis' ),
'id' => 'contactwidget',
'description' => __( 'ContactForm', 'genesis' ),
'before_widget' => '<div class="wrap contact-form-widget">',
'after_widget' => '</div>',
) );
}
add_action( 'widgets_init', 'contact_form_widget' );
//* Add the Contact Form Widget in place
function contact_form_widget_visible() {
genesis_widget_area ('contactwidget', array(
'before' => '<div class="contact-form-widget-wrapper">',
'after' => '</div>',));
}
add_action( 'genesis_before_footer', 'contact_form_widget_visible' );