Forum
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
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
(
So I guess strip_tags is expecting a string and an array is being returned?
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:
Cheers