Forum

Thread tagged as: Question, Addons

Grabbing the blog excerpt to use as the meta description in blog.php

I'm trying to grab the excerpt from the blog templates for use as a meta title, I thought that this would work so I'm not sure what I'm doing wrong...

<!-- Grab the meta-title from the Blog post title -->
<title><?php perch_blog_post_field(perch_get('s'), 'postTitle'); ?></title>

<!-- grab the excerpt, strip it of html tags then use it as meta-description -->
<?php 
      $excerpt = strip_tags(perch_blog_post_field(perch_get('s'), 'excerpt', true));
?>

<meta name="description" content="<?php echo $excerpt ?>">

I'm getting empty output from the excerpt, i.e.

    <!-- Grab the meta-title from the Blog post title -->
    <title>First blog post</title>

    <!-- grab the excerpt, strip it of html tags then use it as meta-description -->

    <meta name="description" content="">

Any ideas? Thanks

Nigel Harding

Nigel Harding 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does the debug output?

OK, so I get this:

DIAGNOSTICS: SELECT * FROM perch2_blog_posts WHERE postStatus='Published' AND postDateTime<='2014-10-02 06:53:00' AND postSlug= '2014-10-01-first-blog-post'

Array

(

[type] => 2

[message] => strip_tags() expects parameter 1 to be string, array given

[file] => /home/ekoimack/public_html/blog/post.php

[line] => 13

So I guess strip_tags is expecting a string and an array is being returned?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It may be easier to run it through a template.

Thanks. That's working fine. So for completeness this is what I did:

Create a new blog template, excerpt.html, which looks like this

<perch:blog id="excerpt" type="textarea" label="Excerpt" markdown="true" order="3" size="s" striptags="true" />

I found it easier to strip the tags in excerpt.html

My post.php contains this:

<meta name="description" content="<?php
  perch_blog_custom(array(
    'template'=>'blog/excerpt.html',
    'count'=>1
)); 
?>">

Cheers