Created
July 5, 2013 22:58
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// 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); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.