How do I echo the first 150 characters of a WYSIWYG?

2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 21, 2017   (RSS)

By Mikey - March 21, 2017

Hey zip222,

Give this a try. You'll need to modify the record referenced and your max words count for your needs... but it should do the trick. I use it in the same manner.

Add MAX Words above your  <!DOCTYPE HTML>.

<?php 
// MAX Words
function maxWords($textOrHtml, $maxWords) {  
  
  $text  = strip_tags($textOrHtml, " ");  
  $words = preg_split("/\s+/", $text, $maxWords+1); 
   
  if (count($words) > $maxWords) { unset($words[$maxWords]); }  
  $output = join(' ', $words);  
   
  return $output;  
}
?>

<!DOCTYPE HTML>

<html>
    <head>

Add as you meta description, and replace "$aboutRecord" with your appropriate record info.

<meta name="description" content="<?php echo maxWords($aboutRecord['content'], 32); ?>" />

Zicky