Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Confused about HTML Meta tags & SEO

Below is the code I wrote for “SEO”-related tweaks. It tries to fill the description meta with something relevant, and adds keywords based on a combination of tags and site-wide words (added via the admin screen). It’s still rough round the edges. For example, it will produce duplicate descriptions on multi-page topics, and descriptions may not be terribly different from the title tag.

<?php
/*
Plugin Name: SEO Tweaks
Description: Adds description and keywords meta to the header.
Author: Tim Howgego
Author URI: http://timhowgego.com/
Version: 0.1.rc
*/

add_action('bb_admin_menu_generator', 'seo_config_menu');
add_action('bb_admin-header.php', 'seo_config_process');

add_action('bb_head', 'seo_meta_description');
add_action('bb_head', 'seo_meta_keywords');

function seo_meta_description() {

switch ( bb_get_location() ) {

case 'topic-page':
$description = get_topic_title()." - ".bb_get_option( 'description' );
break;

case 'forum-page':
$description = get_forum_description();
break;

case 'tag-page':
if ( is_bb_tag() ) {
$description = __('Topics tagged')." ".bb_get_tag_name();
} else {
$description = __('List of tagged topics.');
}
break;

case 'profile-page':
$description = __('Profile for')." ".get_user_display_name()." - ".__('includes contact information and posting history.');
break;

case 'view-page':
$description = get_view_name()." - ".bb_get_option( 'description' );
break;

default:
$description = bb_get_option( 'description' );
break;
}

echo '<meta name="description" content="'.attribute_escape( $description ).'" />'."n";

}

function seo_meta_keywords() {

// Includes enhancements by _ck_

global $tags;
$keywords = array();

if ( !empty( $tags ) ) {
foreach ( $tags as $t ) {
$keywords[] = $t->raw_tag;
}
}

$default_keywords = bb_get_option( 'seo_keywords' );

if ( count( $default_keywords ) >0 ) {
$keywords[] = $default_keywords;
}

if ( count( $keywords ) >0 ) {
echo '<meta name="keywords" content="'.attribute_escape( implode( ", ", $keywords ) ).'" />'."n";
}
}

function seo_config_menu() {
bb_admin_add_submenu(__('SEO'), 'manage_plugins', 'seo_config_page');
}

function seo_config_page() {

?>
<h2><?php _e('SEO Tweaks Configuration'); ?></h2>

<form class="options" method="post" action="">

<fieldset>
<p><strong><label for="seo_keywords"><?php _e('Default keywords') ?></label></strong> (<?php _e('these words will be attached to every page, so only use words that describe the forum's overall content'); ?>):</p>
<textarea name="seo_keywords" id="seo_keywords" cols="100" rows="4"><?php bb_form_option( 'seo_keywords' ); ?></textarea>
<p><?php _e('Separate keywords with a comma. No formatting.'); ?></p>
</fieldset>

<fieldset>
<?php bb_nonce_field( 'seo_config' ); ?>
<input type="hidden" name="action" id="action" value="update_seo_config" />
<input type="submit" name="submit" id="submit" value="<?php _e('Save Changes &raquo;') ?>" />
</fieldset>

</form>
<?php

}

function seo_config_process() {

if ($_POST['action'] == 'update_seo_config') {

bb_check_admin_referer( 'seo_config' );

if ($_POST['seo_keywords']) {
$value = htmlentities( trim( $_POST['seo_keywords'] ) , ENT_NOQUOTES );
if ($value) {
bb_update_option( 'seo_keywords', $value );
} else {
bb_delete_option( 'seo_keywords' );
}
} else {
bb_delete_option( 'seo_keywords' );
}

$goback = add_query_arg( 'seo_updated', 'true', wp_get_referer() );
bb_safe_redirect( $goback );
exit;
}

if ($_GET['seo_updated']) {
bb_admin_notice( __('Changes saved.') );
}

}

?>

Skip to toolbar