How to include a Meta Description and Keywords in bbpress without a plug-in.
-
So after trying many plug-ins for meta data i found out that most don’t work at all with the newest version of bbpress and others do a poor job so i decided to write my own little php code no plug-in needed.
I wrote some php code to include a meta description based on the first 200 characters of the post and a default description if there is no post ( i.e the front-page ). Also meta keyword’s that displays any tags associated with that post as keywords.
So just add this to your header
<?php
if ($posts) {
foreach ($posts as $bb_post) : $del_class = post_del_class();
$old=ob_get_contents(); ob_clean(); ob_start(); // you may leave ob_start();
post_text();
$out.=ob_get_contents(); ob_clean();
endforeach;
$out = preg_replace('#<p[^>]*>(s| ?)*</p>#', '', $out); // takes out <p>
$out = substr($out,0,200); // only displays the first 200 lines of the first post.
echo '<META NAME="Description" CONTENT="';
echo $out;
echo '">';
}
else {
echo '<META NAME="Description" CONTENT="This is your defalt description edit this to what ever you want ">'; // This displays when where is no post
}
global $tags;
if (!empty($tags)) {
$keywords=""; foreach ($tags as $t) {$keywords.=$t->raw_tag.', ';}
echo "n".'<meta NAME="keywords" CONTENT="'.trim($keywords,", ").'">'."n"; // This displays any tags associated with that post as a keyword
} ?>
Viewing 21 replies - 1 through 21 (of 21 total)
Viewing 21 replies - 1 through 21 (of 21 total)
You must be logged in to reply to this topic.