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).

:advice: 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. (y)

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

You can share this post with:


Similar Posts

Previous and Next Post

One Comment »

  1. manpreet says:

    thanks…

Leave a comment

*It won't be visible

Comments with insults and spam will be deleted.
Avatar: If you want your own picture in the comments, just upload it to Gravatar.
HTML: You can use some HTML code as blockquote, a href, strong, em, li and code.

Subscribe without commenting

 
Aeromental 2007 - 2012 ★ ☆ All the best people are crazy ☆ ★