Filtering WP Title
as add_filter, get_bloginfo, how-to, is_frontpage, is_home, WordPress, wp_title
A recent recommendation, starting with WordPress 3.3, from the WordPress Theme Review Team reads:
Themes are REQUIRED to use wp_title filter to filter wp_title() (RECOMMENDED), or pass argument to wp_title() (OPTIONALLY), in order to modify document title content
This has been discussed, worked through, and for the most part sorted out … but there doesn’t appear to be any sort of example code to work from. This presented an opportunity to have a look around the WordPress codex and the source code for some ideas how to filter the `wp_title` function.
Essentially, the idea behind the code (below) is to take a basic function call of `wp_title` add some relevant text (a la default themes: Twenty Ten / Twenty Eleven) then filter it back into the function; and finally to echo this to the HTML <title> tag.
<?php
if ( ! function_exists( 'wpfa_wp_title' ) ) {
/**
* WPFA WP Title
*
* Utilizes the `wp_title` filter to add text to the default output
*
* @package WPFA_WP_Title
* @version 0.2 - last revised April 26, 2012
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title
* @link https://gist.github.com/1410493
*
* @param string $old_title - default title text
* @param string $sep - separator character
* @param string $sep_location - left|right - separator placement in relationship to title
*
* @return string - new title text
*/
function wpfa_wp_title( $old_title, $sep, $sep_location ) {
global $page, $paged;
/** Set initial title text */
$wpfa_title_text = $old_title . get_bloginfo( 'name' );
/** Add wrapping spaces to separator character */
$sep = ' ' . $sep . ' ';
/** Add the blog description (tagline) for the home/front page */
$site_tagline = get_bloginfo( 'description', 'display' );
if ( $site_tagline && ( is_home() || is_front_page() ) )
$wpfa_title_text .= "$sep$site_tagline";
/** Add a page number if necessary */
if ( $paged >= 2 || $page >= 2 )
$wpfa_title_text .= $sep . sprintf( __( 'Page %s', 'wpfa-wp-title-textdomain' ), max( $paged, $page ) );
return $wpfa_title_text;
}
}
add_filter( 'wp_title', 'wpfa_wp_title', 10, 3 ); ?>
Hopefully this will be useful, or maybe it will not … but it will be found in the next release of Desk Mess Mirrored as that is the theme where I first wrote and tested it with.
Enjoy!



Remove Comment Form Website Section
in Functions, Tips
as add_filter, comment_form, how-to, WordPress
From time to time an interesting Five-Minute-FixTM comes along that sparks a great reason to add another WordPress Tips post. The idea for this tip started with this comment at BuyNowShop.com:
The solution may be obvious to some and can be readily derived from the information found on the WordPress codex page for the `comment_form` function, but if you are new to WordPress and/or not familiar with writing a function to use with `add_filter`, here is a very simple and working snippet to use in your theme:
function wpfa_remove_comment_website_section(){ $commenter = wp_get_current_commenter(); $req = get_option( 'require_name_email' ); $aria_req = ( $req ? " aria-required='true'" : '' ); $fields = array( 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>', 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>', 'url' => '' /** removes website section */, ); return $fields; } add_filter( 'comment_form_default_fields', 'wpfa_remove_comment_website_section' );Ideally, this will be placed in the ‘functions.php’ file of your theme, but better yet this should be included in the Child-Theme you created of the theme you want to modify.