Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

jeriksson on "Need some help pulling excerpt from post that doesn't have an excerpt."

$
0
0

Hi,

i'm trying to make my site add automatic information for facebook likes og:image og:Title and such.

can someone explain why this code doesn't work (everything works except the description part)

<?php if (is_single()) { ?>
<meta property="og:title" content="<?php the_title(); ?>"/>
<meta property="og:description" content="<?php $content = get_the_content(); $content = strip_tags($content); echo substr($content, 0, 100); ?>" />
<meta property="og:url" content="<?php the_permalink(); ?>"/>
<?php $fb_image = wp_get_attachment_image_src(get_post_thumbnail_id( get_the_ID() ), 'thumbnail'); ?>
<?php if ($fb_image) : ?>
    <meta property="og:image" content="<?php echo $fb_image[0]; ?>" />
<?php endif; ?>
<meta property="og:type" content="<?php
    if (is_single() || is_page()) { echo "article"; } else { echo "website";} ?>"
/>
<meta property="og:site_name" content="<?php bloginfo('name'); ?>"/>

 <?php } ?>

I'm using <?php $content = get_the_content(); $content = strip_tags($content); echo substr($content, 0, 100); ?> to pull the content and then strip everything beyond 100 characters, but it shows up as nothing in the html source

its also emtpy if i use <?php echo strip_tags(get_the_excerpt($post->ID)); ?> but that's probably because i've not created any excerpts, i'm not sure if excerpts are being automatically generated or if they have to be manually created by default, i'm guessing the second.

Any help on this would be appreciated.


Viewing all articles
Browse latest Browse all 8245

Trending Articles