Tagged: randomize, widget area
-
AuthorPosts
-
December 29, 2014 at 9:31 pm #372820
Hello,
I am looking to do a somewhat advanced modification to the theme. My goal is to randomize the order of widgets in the widget area. This can happen to all widget areas across the site. I found this code
function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "") { $output = ""; if(!isset($atts['widget_area'])) return $output; if( is_dynamic_sidebar( $atts['widget_area'] ) ) { ob_start(); dynamic_sidebar( $atts['widget_area'] ); $output = ShortcodeHelper::avia_remove_autop(ob_get_clean(), true); if($output) $output = "<div class='avia-builder-widget-area clearfix ".$meta['el_class']."'>".$output."</div>"; } return $output; } } }
Is there a way to add in a randomization step to the function?
Thanks in advance!
December 29, 2014 at 9:34 pm #372822This reply has been marked as private.December 29, 2014 at 9:43 pm #372829Hi!
I don’t think that would be possible. The WordPress function for displaying a widget area does not have an option for randomizing the widgets and I could not find any plugins for it either.
@stevewturnbull, Click on “Account Overview” and then go to your subscriptions to delete them. You can also click on “Unsubscribe” when viewing the topic you are subscribed to.Cheers!
ElliottDecember 29, 2014 at 9:50 pm #372834Thanks for the fast response, it would be awesome if you could check out this function. Do you think I could somehow run the array through this.
http://www.wp-code.com/wordpress-snippets/how-to-randomize-the-order-of-widgets/Sorry, edited with correct link, that other code was old.
- This reply was modified 9 years, 11 months ago by theoriginaljordan.
December 29, 2014 at 10:03 pm #372841Hi!
Hmm, that looks like it might work. Try adding it to the bottom of your functions.php file and then replace “sidebar” in the code to “sidebar-1” or “sidebar-2” etc etc.
Cheers!
Elliott- This reply was modified 9 years, 11 months ago by Elliott.
December 29, 2014 at 10:08 pm #372844This reply has been marked as private.December 29, 2014 at 10:14 pm #372851Hi!
It seems to be working fine on my end. I created a custom widget area and it’s the 10th widget area on my setup so I set the sidebar name to “sidebar-10” and it’s randomizing the widgets assigned to this widget area on each page load.
Cheers!
ElliottDecember 29, 2014 at 10:16 pm #372854How do you find out what number the sidebar is? I also didn’t have it at the bottom of my functions.php, so that was probably the problem!
Thanks again so much, life saver!
December 29, 2014 at 10:20 pm #372859Hey!
You just count the total number of widget areas your using.
Cheers!
ElliottDecember 29, 2014 at 10:21 pm #372860This reply has been marked as private. -
AuthorPosts
- The topic ‘Randomize Widget Area’ is closed to new replies.