WordPress Quotes

  • Posted February 21, 2011. Last modified June 16, 2011 by

Just a simple project that prints random quotes anywhere on a wordpress page. Essentially it is just a custom post type that includes the quote and the author. A single function call returns the random quote which can then be displayed wherever you like on your pages. Requires at least version 3.0 of WordPress since I think that is when the custom post types were implemented.

To use the plugin just add the quotes using the WordPress admin interface on your site. Then to get the quotes to display on the site, call:


to display an default styled quote or the quote_random() function which will return an associative array with both the content and author in it like this:

$quote = quote_random();
echo $quote["title"]; //the quote title (if you choose to display this)
echo $quote["content"]; //this is the quote itself
echo $quote["author"]; //this is the author
echo $quote["date"]; //this is the qutoe date

The reason why this format was chosen, was to create the most flexibility for use in a template. It is easy to stick these inside of a div or apply css styling to it.

Update: Many people have asked questions about where to put the above code in their templates. If you would like the code to show up in your header, look for a header.php file in your template source. Next look for a section with something like this:

Usually you can insert it somewhere near this to get it into your header.

Alternatively, if your theme / template uses widgets, the simple quotes plugin also supports this, so you can add random quotes even easier for those without much experience working with php / html / css.

Here is the plugin page on the wordpress plugin repository: http://wordpress.org/extend/plugins/simple-quotes/

20 comments on “WordPress Quotes”


    Great little plugin, thanks. If you were to improve this, I’d recommend using the title for a short name for the quote and using a textarea for the quote itself. That would avoid long URLs (which don’t matter in my case) and let people see the full quote without having to manually scroll to the right of the title/headline field. And it would let people put HTML A tags, bold, and other markup for each quote the same as any edit textarea.


    hi buddy, i am using antinews options theme and not sure where to insert the code and how exactly? please help.


      Hey, you can stick something like this in the header.php file:

      < ? quote_display_random() ?>

      Put it right after:

      < ?php if(($taglineposition == "left") || ($taglineposition == "center")){?>< ?php $showhideslogan=$AntisnewsOptions[$themeoptionsprefix.'_style_showhide_tagline']; if($showhideslogan != 'hide') { $blogdescription=get_bloginfo('description'); if(!empty($blogdescription)){ ?>

      < ?php bloginfo('description');?>

      < ?php } } ?>< ?php }?>

      Which is rougly line 62/63 in the version of the theme that I downloaded….you can see what it looks like on a test site I set up quick here: dev.jasonernst.com/wordpress/.


    Could you please tell me how to get the quotes to display in the sidebar of my website. I have tried pasting ‘quote_random()’ into the text widget but this didn’t work. Is there an easy way to do this?



      Hey, the text widget will likely not work since it only accepts text and html. You could try using this plugin: http://wordpress.org/extend/plugins/php-code-widget/ which allows for php code to be included in a widget and then for the content of the widget, you could do something like < ?php random_quote(); ?>

      I will see if I can add a widget to the next version of the plugin so that it will be as simple as adding a quote widget, and you will get a random quote showing up. Cheers!


      I have updated to a new version – 1.05 which now supports widgets better…there should be a new widget type called “Simple Quotes Widget” which you can drag to get a random quote


    Hello Jason ! Nice plugin, thank you !

    Some questions :
    – I have no “Author” column in the Dashboard, only date (see here : http://imageshack.us/photo/my-images/40/capture2mz.jpg/), why ?
    – Il use the Erudit theme (http://wordpress.org/extend/themes/the-erudite), could you tell me where I can insert the code to have quote next to the title, align right, or under the title, align left (see here : http://imageshack.us/photo/my-images/580/capture3yi.jpg/)

    (Some suggestions :
    – choice of non-italic style for quotes/authors
    – addition of “source” (title)
    – ajax for random quotes ? ;)… Or at least a link to display another/the next quote)

    Thanks for your help.


      Hey thanks for the comment, the author and some other fields only shows up once you click on the individual quote. In the table it just shows the default information the same way as a wordpress post. I suppose I could look into adding more information into that table in a future release.

      Also you have some good suggestions regarding what could be controlled in terms of style. I will include them in the next release.

      For your individual theme, I will take a look and let you know when I get a chance where to put the the code.

      PS: The reason your comment took a couple of days to appear is because I approve all of the comments individually and I didn’t get around to it until now.


      Hey so for your theme, you need to modify the header.php file. For right aligned quotes underneath this line:

      < ?php bloginfo('name') ?>

      stick in:

      < ? quote_display_random();?>

      Of course you can also stick other css in the style if you want to change the size or color, or if you want to move the quote down or up (using margin-top and margin-bottom)


        At last, I’ve took the time to do this, it works, THANK YOU !
        Something I don’t understand : my quotes are all displaying quotation marks (before and after the quote) : is there a way to remove it ?
        (A suggestion : replace the hypen [between author and date], by a en-dash.)


          Problems are solved : I deleted the quotation marks on line 339 (in “index.php” of the plugin). And I replaced the hypen on line 331 ({ echo ” – “; }).

          Thanks again for your great work !


    I just updated the plugin & now the quotes are on separate lines above & below the quoted text? I’m a total newb, so i have no idea how to fix this.
    Love this plugin. Thanks


    I have list of 366 quotes, dated one for every day of the year. 2 Questions:
    1 – Is there a way to import them, in xls or csv?
    1 – Is there a way to display the current day quote rather than random?


    Hi Jason!

    I’m using your widget for my work’s webpage, we already use the /quote subpage as our ‘get a quote’ page. How can i fix it so everything is stored in something like /testimonials or /quotes instead of /quote?


    Hi, Just testing the plugin. I do like it, and using a custom post type certainly improves the functionality for some of the things I do. I have about a dozen Parish Church Websites and I use quotes on most of them. Using a custom post type allows me to include a small image which is good for presentation.

    I am not sure if it is possible at the moment or if this would be an enhancement, however I would like to use categories or tags and allow the random quote widget to filter its selection to a category or a tag.

    That would, I think, enable me to match quotes to the season of the Church Year, (Advent, Christmas, Epiphany, Lent, Easter, etc) and display the quotes according to the season. It would be a manual step to change the widget according to the season. On other sites it might allow the display of a selection from a sub set according to the page that was being displayed, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.