Skip to content

Instantly share code, notes, and snippets.

@R3V1Z3
Created July 5, 2013 22:58
Show Gist options
  • Save R3V1Z3/5937751 to your computer and use it in GitHub Desktop.
Save R3V1Z3/5937751 to your computer and use it in GitHub Desktop.
WordPress snippet to automatically change site tagline(blog description) once a day to a random item from an array. Relies on wp_schedule_event and WordPress action hooks.
<?
// create new schedule_change action hook
add_action('schedule_change', 'change_description');
// function to schedule event if it doesn't exist
function activate_change() {
// check if schedule_change action/event already exists
if ( !wp_next_scheduled( 'schedule_change' ) ) {
// schedule new event to trigger schedule_change daily
wp_schedule_event( time(), 'daily', 'schedule_change');
}
}
// call the change after global WP class object is set up
add_action('wp', 'activate_change');
// function to change the tagline/description
function change_description() {
// array of descriptions, anything you want
$description_list = array(
"Something clever here.",
"Nothing new under the sun.",
"Everything you ever dreamed of."
);
// pick new description from array
$new_description = $description_list[array_rand($description_list)];
// update site tagline (blogdescription) in database
update_option( 'blogdescription', $new_description);
}
?>
@saintbump
Copy link

Good day, how exactly would I implement this into the latest WordPress release and get it to function correctly? Any assistance would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment