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 zip222 - March 21, 2017
How do I echo the first 150 characters of a WYSIWYG?
I am trying to use the content for a meta description tag.
I will need to strip out any HTML.
thanks :)
<?php echo $page['content']; ?>
change to...
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