Random Posts on Homepage
-
I am trying to randomize my posts on the homepage. I prefer not to use a plugin unless it keeps my theme’s formatting. I’ve tried a few “solutions” I found on Google. One solution I tried, works with another theme, but not my current theme.
add_action('pre_get_posts','alter_query'); function alter_query($query){ if ($query->is_main_query() && is_home()) $query->set('orderby', 'rand'); //Set the order to random }
The above code works fine, for one theme. But on my current theme, I get a syntax error message.
If there’s a plugin that simply randomizes the homepage and doesn’t change the current style, please let me know. Thank you.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Random Posts on Homepage’ is closed to new replies.