How to add a random sentence in a WordPress Blog using Theme Functions
If you want to put in your WordPress blog random famous quotes, or any sentence, I found a way to do it without installing plugins or FTP uploading PHP and TXT files, no Data Base insertions aren’t done either.
The sentence will randomly change every-time the page is loaded or refreshed.
You just have to create a new function in your functions.php (Theme Functions).
If you don´t have this file, just copy the functions.php included in the WordPress Classic Template.
Code for the Random Sentence
Insert the following code in functions.php:
function random_sentence() {
$quotes = array(
"Sentence 1",
"Sentence 2",
"Sentence 3"
);
echo $quotes[rand(0, count($quotes) - 1)];
}
You can add as many sentences as you like, the code will automatically detect and count them to randomly show one.
Insert the random sentence in your blog template
To show the sentence in your header, sidebar or footer, just call the new function with this code:
<?php random_sentence(); ?>
That’s all, you can give it any CSS style if you like.
In Aeromental
In Aeromental’s footer (at the very bottom) you can see a random phrase.
If you like, you can suggest new phrases in the comments.
Follow us in Twitter @aeromentaln and Facebook
Post author: Daniel Semper
thanks…