I have a sidebar which might have any number of widgets. I can count the number of widgets that exist in the sidebar. How do I display randomly only one of the widgets in my sidebar at each page load?

Use: We have specials which we display as widgets, but we only want to display one widget’s content at a time in the footer of the site.

re: the count code

<?php $the_sidebars = wp_get_sidebars_widgets();
echo count( $the_sidebars['center-footer'] ); ?>

re: generating a random widget instance

<?php echo rand(1, count( $the_sidebars['center-footer'] )); ?>

Read more here: Randomize widgets displayed in my sidebar


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , ,

Wordpress related questions and answers: