Re: How to include a Meta Description and Keywords in bbpress without a plug-in.
Cripes, no need for all that object-based markey, bbPress has functions to pass as a string rather than echo…
<?php
/*
Plugin Name: Meta Headers
*/
function meta_heads() {
global $posts, $tags;
if ( $posts ) {
$out = $posts[0]->post_text;
$out = strip_tags( $out );
$out = str_replace( array( "n", "r" ), ' ', $out );
$out = substr($out, 0, 200); // only display the first 200 characters of the first post
}
if( empty( $out ) )
$out = 'Default description';
echo "n".'<meta name="description" content="'.$out.'" />';
if ( !empty( $tags ) ) {
$keywords = '';
foreach ($tags as $t) {
$keywords.=$t->raw_tag.', ';
}
echo "n".'<meta name="keywords" content="'.substr($keywords,0,-2).'">'."n"; // displays any tags associated with a topic as keywords
}
}
add_action( 'bb_head', 'meta_heads' );
That will strip HTML, but not bbCode