• Resolved BB1975

    (@bb1975)


    Hi Paul, amazing plugin.

    I had a quick question regarding the title functionality. Is it possible to automatically use the first several words as the title, instead of requiring the user to submit a custom title? I like how the title looks on the page, but would prefer to limit the fields a user has to deal with when submitting a review.

    Thanks in advance for your help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    Add the following code to your theme’s functions.php file:

    /**
     * Replaces the title of a review with the first few words of the review text
     * @param object $review
     * @return object
     */
    add_filter( 'site-reviews/get/review', function( $review ) {
        $limit = 7; // change this number to the desired number of words
        $split = 0;
        if( str_word_count( $review->content, 0 ) > $limit ) {
            $words = array_keys( str_word_count( $review->content, 2 ));
            $split = $words[$limit];
        }
        $review->title = substr( $review->content, 0, $split );
        return $review;
    });
    • This reply was modified 6 years, 6 months ago by Gemini Labs.
    • This reply was modified 6 years, 6 months ago by Gemini Labs.
    Thread Starter BB1975

    (@bb1975)

    Thanks, Paul! What’s the best place to insert that code in the functions.php file —?does it matter?

    Plugin Author Gemini Labs

    (@geminilabs)

    It does not matter.

    Thread Starter BB1975

    (@bb1975)

    Incredible support —?thank you so much.

    Thread Starter BB1975

    (@bb1975)

    Hi Paul, one more quick question: How do I add “…” immediately following the title text?

    Plugin Author Gemini Labs

    (@geminilabs)

    $review->title = substr( $review->content, 0, $split ).'…';
    
    Thread Starter BB1975

    (@bb1975)

    Thanks, Paul! Is there a way to eliminate the blank space between the last word in the title and the “…”?

    Plugin Author Gemini Labs

    (@geminilabs)

    $review->title = trim(substr( $review->content, 0, $split )).'…';
    
    Thread Starter BB1975

    (@bb1975)

    Brilliant. Thank you, Paul!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Title customization question…’ is closed to new replies.