• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2665

Original Genesis Tutorials & 5000+ Guaranteed Code

Snippets

  • Support
  • Newsletter
  • Videos
  • Log in

Premium Member? - Request custom code

Random Recent Posts Widget Code

This code simply creates a duplicate of the native recent posts widget in WordPress which also includes an additional parameter for ordering your recent posts randomly.

Copy the code from the view raw link and paste at the end of your functions file.

You can use any of the WP_Query parameters in this part of the code to extend the widget modification further.

$r = new WP_Query( apply_filters( 'widget_posts_args', array(
			'posts_per_page'      => $number,
			'no_found_rows'       => true,
			'post_status'         => 'publish',
			'orderby'             => 'rand',
			'ignore_sticky_posts' => true
		 ) ) );

Related Posts

  • Modify Native Recent Posts Widget Output Using widget_posts_args Filter

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

PHP Code

template_include

get_body_class

if else

array

class_exists

foreach

sprintf

add_action

printf

variable

Advertise · WPEngine · Genesis · Log in

  • How Premium Membership Works
  • Sign Up
  • Support
  • Subscription Details/Invoice
  • Tagged Tutorials
  • Access-Download Problems