I'm using a plug-in ("Wordpress plugin random post slider") for Wordpress that pulls a random post from a category, and displays it in a slider for use as a shortcode or php code in a template.

I've already made some modifications to the plug-in to get it to display properly on my site (http://lillypillyps.com.au), but it has some limitations that the developer will take forever to follow up on.

I was wondering if someone might be able to help with the following questions in order of importance:

  1. it's using some sort of truncate on the post content which is currently set to 170 characters (through the plug-in's settings page in the admin of WP). I want it to truncate to the nearest word so it doesn't cut-off mid-word.

  2. is it possible to ONLY have the "... READ MORE" button display IF the content is longer than the truncation point? ie. not display if the content is less that 170 characters.

  3. there is a few options for the transitions between the slides (scrollLeft/scrollRight/scrollUp/scrollDown), but the same jquery should be capable of fade-in/fade-out shouldn't it? How can I used this transition instead of the ones the plug-in "allows" me to use?

1 Answer 1


This is a rather sloppily coded plugin, unfortunately. However, to answer your questions:

  1. Replace the function gopiplus_clean with this

    function gopiplus_clean( $excerpt, $length = 0 ) {
    $string = strip_tags( str_replace( '[...]', '...', $excerpt ) );
    if ( $length > 0 ) {
        $words_array = preg_split( "/[\n\r\t ]+/", $excerpt, $length + 1, PREG_SPLIT_NO_EMPTY );
        $words = count( $words_array );
        if ( $words <= $length ) {
            return $excerpt;
        $array = array_slice( $words_array, 0, $length );
        $string = implode( ' ', $array );
    return $string;
  2. Replace if ($displayreadmore == "YES") (in 2 places) with

    if ($displayreadmore == "YES" && (str_word_count($post_content) > $displaydesc)) 
  3. Just enter 'fade' into the settings instead of the slide versions. It will work.

  • I thought as much... I've just tried your code replacement for #1 (I removed a bunch of extra spaces either sides of the brackets), but the truncation no longer works at all. I changed the "Content Length" in the admin panel for the plugin to 5 (in case it now referred to words rather than characters), but it didn't affect anything.
    – Reece
    Commented Apr 3, 2013 at 1:13
  • the code replacement for #2 stops the "read more" showing altogether... Maybe I have missed something?
    – Reece
    Commented Apr 3, 2013 at 1:14
  • #3 - changing to fade works! thanks. But - it is now showing all the content whereas it used to hide overflow text that went outside the boundaries of the DIV.
    – Reece
    Commented Apr 3, 2013 at 1:16
  • #1 works fine for me (tested on a fresh install of WP). The 'extra spaces' are correct WP coding convention, but won't affect the result either way. #2 also works fine for me. I'm not sure about the issue with #3, this might be specific to your content.
    – vancoder
    Commented Apr 3, 2013 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.