Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author thaikolja

    (@thaikolja)

    Are you using “Auto show” or do you use the PHP function to manually insert?

    Thread Starter DruidSolutions

    (@druidsolutions)

    Im using PHP function.

    Plugin Author thaikolja

    (@thaikolja)

    Try this:

    <?php
       $secondary_title = get_secondary_title();
       $maximum_words   = 5;
    
       /** We do this if the secondary title contains a full stop */
       if(strstr($secondary_title, ".")) {
          /** Split the string into an array wherever a full stop occurs */
          $parts = explode(".", $secondary_title);
    
          /** Use the first part as new secondary title and drop the rest */
          $secondary_title = $parts[0];
    
          /** If you want to add the full stop, remove the // from this line */
          // $secondary_title .= ".";
       }
       else {
          /** Split string into an array wherever a space occurs */
          $parts = explode(" ", $secondary_title, $maximum_words + 1);
    
          /** Check if found spaces equal at least $maximum_words + 1 */
          if(count($parts) >= $maximum_words + 1) {
             /** Shorten the array to $maximum_words */
             $parts           = array_splice($parts, 0, $maximum_words);
    
             /** Glue the parts back together into a string */
             $secondary_title = implode(" ", $parts);
          }
       }
    
       echo $secondary_title;
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Limit number of words’ is closed to new replies.