Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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!

    #372822
    This reply has been marked as private.
    #372829

    Hi!

    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!
    Elliott

    #372834

    Thanks 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.

    #372841

    Hi!

    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.
    #372844
    This reply has been marked as private.
    #372851

    Hi!

    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!
    Elliott

    #372854

    How 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!

    #372859

    Hey!

    You just count the total number of widget areas your using.

    Cheers!
    Elliott

    #372860
    This reply has been marked as private.
Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Randomize Widget Area’ is closed to new replies.