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

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.

Leave a Reply