We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Configuration, Addons

Blog Article Excerpt Reused

I am trying to reuse the blog article excerpt as the meta description.

Should I create a separate layout for the head content just for the blog post or create a different seo.html changing the content id for the blog excerpt?

I tried this in a blog head content:

<meta name="description" content="<?php perch_blog_post_field(perch_get('s'), 'excerpt', striptags=true); ?>" />

But while it output the text okay it had <p> tags around it, however I think its coded wrong as my editor is showing an error.

Can you advise?

Nigel Coath

Nigel Coath 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You should use a template - then you can add the striptags attribute you're attempting to implement.

How would I pull in an article excerpt in a template?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Create a template containing the excerpt tag.

Use perch_blog_custom() to display the post using that new template.

Okay I have got it working by adapting my original code:

<meta name="description" content="<?php perch_blog_post_field(perch_get('s'), 'excerpt'); ?>" />

and changing the code in the post.html to

<perch:blog id="excerpt" type="textarea" textile="false" html="false" escape="true" striptags="true" />

It works, however some characters are not outputting correctly e.g. an ampersand is ' the only way I can avoid this currently is using the Æ character. Any ideas what I can do to translate this character?

? and ! output fine.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you have an example?

<meta name="description" content="2015 is rapidly approaching, a fresh start, a new opportunity? We all know about New Year's resolutions, perhaps this year is the year you expand your business, or regenerate it, or maybe start a new one?" />

I think its something to do with html entities? Maybe this is just the way it is?

BTW I typed

&#039;

but it translated in the post correctly as a '

Thats what I want to happen when it is in the meta description.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm sorry, I know you're explaining it, but I really can't grasp the problem. I'll try fresh in the morning!