Support » Themes and Templates » Change order of widgets display on site

  • So what I want is that the widgets are displayed in a random order in the sidebar. I’m sure a few lines of php in my function file or even in the sidebar file should be enough. I played around with wp_get_sidebars_widgets() and shuffle() bit, but I can’t find the WP hooks/functions which allow me to change the order.

    Any ideas?

Viewing 1 replies (of 1 total)
  • Ok so in the meantime I got it working. However, I’m not sure about the method

    $wdg = wp_get_sidebars_widgets();
    $primary_widgets = $wdg['primary'];
    shuffle($primary_widgets);
    $wdg['primary'] =  $primary_widgets;
    wp_set_sidebars_widgets($wdg);

    This works, but it doesn’t only shuffle the visual display of the widgets on output, it actually changes the order of the widgets in the database, for each page refresh of the website. I would prefer a method which would just
    – get the widgets for the sidebar
    – randomly change the order
    – display

Viewing 1 replies (of 1 total)
  • The topic ‘Change order of widgets display on site’ is closed to new replies.