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
Related
I have a sidebar in WordPress I've registered like so:
register_sidebar(array(
'id' => '404',
'name' => __('404', 'jointstheme'),
'description' => __('The 404 sidebar.', 'jointstheme'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
));
I duplicated my existing 'sidebar.php' file and created a file called: sidebar-404.php.
I also added the call to my sidebar in the 404 page template like so:
<?php get_sidebar('404'); ?>
Yet for some reason, my theme keeps defaulting to the default sidebar.
Anyone have any ideas what might be going on?
Thanks!
When you register a sidebar in your functions.php file and want to use the widget manager in from the admin panel, you need to use dynamic siderbars not get_sidebar. get_sidebar will only display the widgets that are coded into the file.
Instead of <?php get_sidebar('404'); ?> you should have something like <?php dynamic_sidebar( '404' ); ?>
I'm currently coding my own one page wordpress theme (based on underscores) and I'm trying to add a widget to a page, so this widget will show up on my homepage.
I used this page as my guide; http://codex.wordpress.org/Widgetizing_Themes but the widget is not showing up on my homepage.
Steps I took:
1. Create a custom page template, this is the code of that:
<?php
/*
Template Name: Widget Page
*/
get_header(); ?>
<div id="primary" class="content-area">
<?php putRevSlider("video","homepage") ?>
<main id="main" class="site-main" role="main">
<?php dynamic_sidebar( 'widget-page' ); ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Seems to work fine, I can select the template and the content of my page shows up on the homepage. (See test widget, test test test)
I added the line that calls on the widget there too, as you can tell.
Then I added this to my functions.php;
/**
* Register our sidebars and widgetized areas.
*
*/
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'Widget Page',
'id' => 'widget-page',
'before_widget' => '<div>',
'after_widget' => '</div>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
And I think that's where it's going wrong? The mentioning of a sidebar confuses me a little as this is supposed to show up on a page. The wp guide also mentions a code where it checks if the sidebar is active, but since I'm not putting it in a sidebar I'm not sure if I should use this? I tried using this piece but that also didn't work, which is why I think the problem would be in the functions.php file. The underscores framework also comes with their own piece of widget code, is this causing problems?
/**
* Register widget area.
*
* #link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
function otto_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'otto' ),
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
}
add_action( 'widgets_init', 'otto_widgets_init' );
This is a link to my page; http://kellyvuijst.nl/onepage/
Thanks in advcance!
After some more googling I found out the easiest option to make a widget appear in a page is to make sure you can short code widgets and then just add the short code to the page. No custom templates needed.
This is the code I used in my functions.php;
function widget($atts) {
global $wp_widget_factory;
extract(shortcode_atts(array(
'widget_name' => FALSE
), $atts));
$widget_name = wp_specialchars($widget_name);
if (!is_a($wp_widget_factory->widgets[$widget_name], 'WP_Widget')):
$wp_class = 'WP_Widget_'.ucwords(strtolower($class));
if (!is_a($wp_widget_factory->widgets[$wp_class], 'WP_Widget')):
return '<p>'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'<strong>'.$class.'</strong>').'</p>';
else:
$class = $wp_class;
endif;
endif;
ob_start();
the_widget($widget_name, $instance, array('widget_id'=>'arbitrary-instance-'.$id,
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
));
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode('widget','widget');
Which I found thanks to; https://digwp.com/2010/04/call-widget-with-shortcode/
Problem solved!
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"); ?>
In wordpress widgets I have a "Image" widget. It has:
Title
The image you uploaded or want to upload
The size
The link
The link text
Now I want to know, is there a hook or something i can use to grab that "link" from the saved widget? See below. On the 4th line I want to display the link from that image widget here where it says THIS IS WHERE I WANT TO GET THAT LINK HERE.
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Other Serviecs Page Widget',
'before_widget' => '<a href="THIS IS WHERE I WANT TO GET THAT LINK HERE"><div class="col-sm-6 col-md-3">
<div class="add-box-main"> ',
'after_widget' => '<div class="box-bottom"> </div>
</div>
</div>',
'before_title' => '<div class="box-heading"> <img src="../wp-content/uploads/2014/10/OS-LOGO.jpg" class="img-responsive" alt=""><h2>',
'after_title' => '</h2></div>',
));
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Other Serviecs Page Bottom Widget',
'before_widget' => '</a>',
'after_widget' => '',
'before_title' => '<h1 class="hide">',
'after_title' => '</h1>',
));
Widget settings are stored in the options table. You can get the content of an option field with get_option(). Replace MY_WIDGET with the actual ID of your widget:
$widget = get_option( 'widget_MY_WIDGET' );
Use print_r to inspect the returned value (false if option does not exist) and get an idea of how to grab the desired value:
print_r( $widget );
Have you looked at wp_get_attachment_url in the Wordpress codex? Here's the link: http://codex.wordpress.org/Function_Reference/wp_get_attachment_url
That will return the full path to the image file assuming that there's a loop running.
Let me know if that helps.
I'm building a site into which I'm incorporating a wordpress blog and during my customisation of a theme I've run into a slight snag.
I'm using a couple of widgets in the footer to display recent posts etc but they are displaying with their own inline styling. I can't find anywhere that may be adding the styling but I have found the function in the functions.php file that adds the id and class for the elements in question and I'm wondering whether I can add some php to the function in order to remove the styling that follows:
code is as follows:
function twentythirteen_widgets_init() {
register_sidebar( array(
'name' => __( 'Main Widget Area', 'twentythirteen' ),
'id' => 'sidebar-1',
'description' => __( 'Appears in the footer section of the site.', 'twentythirteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
the on-page code is like this:
<aside id="recent-posts-2" class="widget widget_recent_entries masonry-brick" style="position: absolute; top: 0px; left: 0px;">
so i want to leave the id and class but just strip out the "style" elements
I know php may not be the best way to do this so i'm open to suggestions but if i can pop a preg replace or reg ex etc into the function that would be great.
Cheers guys
I had this problem earlier and as suggested in the comments by #Damien Pirsy, the issue was that the masonry jquery plugin was enqueued in the theme's functions.php file like so:
<?php
// Remove the following
if ( is_active_sidebar( 'sidebar-3' ) ) {
wp_enqueue_script( 'jquery-masonry' );
}
?>
This is a relic from the original WordPress twentyfouteen theme so make sure to test well after you remove it.