Home  >  Article  >  CMS Tutorial  >  How to make WordPress side widgets sort randomly

How to make WordPress side widgets sort randomly

藏色散人
藏色散人Original
2019-11-21 10:48:482708browse

The following column WordPress Tutorial will introduce to you how to randomly sort WordPress side widgets. I hope it will be helpful to friends in need!

How to make WordPress side widgets sort randomly

Sometimes you may want the sidebar widgets to be displayed in random order. You can add the following code to the end of the current theme template functions.php file:

add_filter ('sidebars_widgets', 'zm_randomize_widget_order');
function zm_randomize_widget_order($sidebars_widgets) {
	if (!is_admin()) {
		foreach ($sidebars_widgets as &$widget) {
			shuffle ($widget);
		}
	}
	return $sidebars_widgets;
}

Randomly sorting through front-end widgets can make your website layout constantly changing and display different content to viewers from time to time, thereby increasing the number of article reads.

The above is the detailed content of How to make WordPress side widgets sort randomly. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn