• Resolved eassae

    (@eassae)


    Hello,

    I am trying to use my post excerpt as og:description meta data. I am using some code I found with a minor modification. The problem I am having is that post_excerpt seems to return nothing.

    Any help would be appreciated.

    <?php
    function og_meta_desc() {
    	global $post;
    	$meta = strip_tags($post->post_excerpt);
    	$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
    	$meta = substr($meta, 0, 200);
    	if ( $meta != '' ) {
    		echo "<meta property=\"og:description\" content=\"$meta\" />";
    	} else {
    		echo "<meta property=\"og:description\" content=\"WTF\" />";
    	}
    }
    og_meta_desc();
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter eassae

    (@eassae)

    Solved:

    <?php
    function og_meta_desc() {
    	global $post;
    	$meta = strip_tags($post->post_content);
    	$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
    	$meta = substr($meta, 0, 200);
    	if ( $meta != '' ) {
    		echo "<meta property=\"og:description\" content=\"$meta...\" />";
    	} else {
    		echo "<meta property=\"og:description\" content=\"$Here is some cool new content.  Check it out.\" />";
    	}
    }
    og_meta_desc();
    ?>
    Thread Starter eassae

    (@eassae)

    Final:

    <?php
    function og_meta_desc() {
    	global $post;
    	$meta = strip_tags($post->post_content);
    	$meta = strip_shortcodes($meta);
    	$meta = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), ' ', $meta);
    	$meta = substr($meta, 0, 200);
    	if ( $meta != '' ) {
    		echo "<meta property=\"og:description\" content=\"$meta...\" />";
    	} else {
    		echo "<meta property=\"og:description\" content=\"Here is some cool new content.  Check it out.\" />";
    	}
    }
    og_meta_desc();
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Using the_excerpt as meta’ is closed to new replies.