Separating message and author in ‘Stray Random Quotes’ WordPress plugin

In: Feeling guru|Techie Daw|wordpress

30 Jan 2011

I needed a plugin that can show random quotes with author options as well and I found Stray Random Quotes WordPress plugin could do the trick. The only problem is, the function to display the random quote directly outputs the text onscreen together with the author.

What I need to do is to suppress the display of the function output onscreen, pass it to a variable then do a split of the variable to separate the message and author in an array. See the code below on how I did it 🙂

<?php 
if (function_exists('stray_random_quote')) 
// turn on output buffer
ob_start(); 
// run the function of the plugin
stray_random_quote('feedback',false,'',true,1,0,'Category','ASC',false,''); 
// get the content from the buffer
$string = ob_get_contents(); 
ob_end_clean();
// split the output and remove unnecessary HTML tags
$feedback = split('by',strip_tags($string));
// access the message
echo trim($feedback[0]);
// access the author
echo trim($feedback[1]);

Pretty easy!

About the author

Richard Feraro is a Magento Enterprise Certified developer from Manila, Philippines with 14 years of solid open-source development experience using Linux, Apache, MySQL & PHP.

1 Response to Separating message and author in ‘Stray Random Quotes’ WordPress plugin

Avatar

Semidoppel PHILIPPINES

February 1st, 2011 at 4:52 pm

More more teach me more pls! Hehehe actually kht HTML di akomarunong

Comment Form

About my blog

This blog is targeted towards all levels of developers and also designers. Various topics are discussed such as Magento, PHP & MySQL, jQuery, WordPress, CSS and HTML.

Booking.com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 5,243 other subscribers

WordPress + Magento

Recent Trackbacks

Archives

Disclaimer

All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or my mom.