This code snippet transforms the code of the hello dolly plugin into a random announcement that displays at the top of our admin pages. Refer to the above video for customization.
/* Add Random Admin Announcement */
function hello_dolly_get_lyric() {
/** These are my random announcements */
$lyrics = "Remember to change your password regularly.
Visit the developer tips website at <a target='_blank' href='http://baguiowebs.com'>http://whatever-domain.com</a>
Another random quip
Yet another random quip";
// Here we split it into lines
$lyrics = explode( "\n", $lyrics );
// And then randomly choose a line
return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] );
}
// This just echoes the chosen line, we'll position it later
function hello_dolly() {
$chosen = hello_dolly_get_lyric();
echo "<p id='dolly'>$chosen</p>";
}
// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'hello_dolly' );
// We need some CSS to position the paragraph
function dolly_css() {
// This makes sure that the positioning is also good for right-to-left languages
$x = is_rtl() ? 'left' : 'right';
echo "
<style type='text/css'>
#dolly {
float: $x;
padding-$x: 15px;
padding-top: 5px;
margin: 0;
font-size:20pt;
background-color:#FF0;
color:blue;
}
</style>
";
}
add_action( 'admin_head', 'dolly_css' );