Skip to content

Commit

Permalink
Moving more Hybrid theme stuff out of core.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.locallylost.com/themes/hybrid-core/trunk@363 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information
greenshady committed Oct 12, 2010
1 parent 4ca6422 commit e674efb
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 188 deletions.
24 changes: 10 additions & 14 deletions classes/hybrid.php
Expand Up @@ -58,6 +58,10 @@ function init() {
/* Load theme extensions later since we need to check if they're supported. */
add_action( 'after_setup_theme', array( &$this, 'extensions' ), 12 );

/* Load the default action and filters after the theme is set up. */
//add_action( 'after_setup_theme', array( &$this, 'actions' ), 13 );
//add_action( 'after_setup_theme', array( &$this, 'filters' ), 13 );

/* Load theme textdomain. */
$domain = hybrid_get_textdomain();
$locale = get_locale();
Expand Down Expand Up @@ -173,6 +177,9 @@ function extensions() {

/* Load the Post Layouts extension if supported. */
require_if_theme_supports( 'post-layouts', HYBRID_EXTENSIONS . '/post-layouts.php' );

/* Load the temporary core SEO component. */
require_if_theme_supports( 'hybrid-core-seo', HYBRID_FUNCTIONS . '/core-seo.php' );
}

/**
Expand Down Expand Up @@ -208,20 +215,9 @@ function actions() {
remove_action( 'wp_head', 'wp_generator' );

/* Head actions. */
$actions[] = 'wp_generator';
$actions[] = 'hybrid_meta_template';
if ( current_theme_supports( 'hybrid-core-seo' ) ) {
$actions[] = 'hybrid_meta_robots';
$actions[] = 'hybrid_meta_author';
$actions[] = 'hybrid_meta_copyright';
$actions[] = 'hybrid_meta_revised';
$actions[] = 'hybrid_meta_description';
$actions[] = 'hybrid_meta_keywords';
}
$actions[] = 'hybrid_head_pingback';

foreach ( $actions as $action )
add_action( 'wp_head', $action, 1 );
add_action( 'wp_head', 'wp_generator', 1 );
add_action( 'wp_head', 'hybrid_meta_template', 1 );
add_action( 'wp_head', 'hybrid_head_pingback' );

/* WP print scripts and styles. */
add_action( 'template_redirect', 'hybrid_enqueue_style' );
Expand Down
161 changes: 161 additions & 0 deletions functions/core-seo.php
@@ -0,0 +1,161 @@
<?php
/**
* Temporary file to hold SEO/<head> stuff until a permanent home is found.
*
* @package HybridCore
* @subpackage Functions
*/

add_action( 'wp_head', 'hybrid_meta_robots', 1 );
add_action( 'wp_head', 'hybrid_meta_author', 1 );
add_action( 'wp_head', 'hybrid_meta_copyright', 1 );
add_action( 'wp_head', 'hybrid_meta_revised', 1 );
add_action( 'wp_head', 'hybrid_meta_description', 1 );
add_action( 'wp_head', 'hybrid_meta_keywords', 1 );

/**
* Sets the default meta robots setting. If private, don't send meta info to the
* header. Runs the hybrid_meta_robots filter hook at the end.
*
* @since 0.2.3
*/
function hybrid_meta_robots() {
if ( !get_option( 'blog_public' ) )
return;

$robots = '<meta name="robots" content="index,follow" />' . "\n";
echo apply_atomic( 'meta_robots', $robots );
}

/**
* Generates the meta author. On single posts and pages, use the author's name.
* On the home page, use all authors. The hybrid_meta_author filter added in 0.6.
*
* @since 0.3.3
*/
function hybrid_meta_author() {
global $wp_query;

$author = '';

if ( is_singular() )
$author = get_the_author_meta( 'display_name', $wp_query->post->post_author );

if ( !empty( $author ) )
$author = '<meta name="author" content="' . esc_attr( $author ) . '" />' . "\n";

echo apply_atomic( 'meta_author', $author );
}

/**
* Add the meta tag for copyright information to the header. Single
* posts and pages should display the date written. All other pages will
* show the current year. The hybrid_meta_copyright filter added in 0.6.
*
* @since 0.4
*/
function hybrid_meta_copyright() {
$domain = hybrid_get_textdomain();

if ( is_singular() )
$date = get_the_time( __( 'F Y', $domain ) );
else
$date = date( __( 'Y', $domain ) );

$copyright = '<meta name="copyright" content="' . sprintf( esc_attr__( 'Copyright (c) %1$s', $domain ), $date ) . '" />' . "\n";
echo apply_atomic( 'meta_copyright', $copyright );
}

/**
* Add the revised meta tag on single posts and pages. This shows the
* last time the post/page was modified. The hybrid_meta_revised filter
* added in 0.6.
*
* @since 0.4
*/
function hybrid_meta_revised() {
$revised = '';

if ( is_singular() )
$revised = '<meta name="revised" content="' . get_the_modified_time( esc_attr__( 'l, F jS, Y, g:i a', hybrid_get_textdomain() ) ) . '" />' . "\n";

echo apply_atomic( 'meta_revised', $revised );
}

/**
* Generates the meta description. Checks theme settings for indexing, title,
* and meta settings. Customize this with the hybrid_meta_description filter.
*
* @since 0.2.3
*/
function hybrid_meta_description() {
global $wp_query;

if ( is_home() ) {
$description = get_bloginfo( 'description' );
}

elseif ( is_singular() ) {
$description = get_metadata( 'post', $wp_query->post->ID, 'Description', true );

if ( empty( $description ) && is_front_page() )
$description = get_bloginfo( 'description' );

elseif ( empty( $description ) )
$description = get_post_field( 'post_excerpt', $wp_query->post->ID );
}

elseif ( is_archive() ) {

if ( is_author() )
$description = get_the_author_meta( 'description', get_query_var( 'author' ) );

elseif ( is_category() || is_tag() || is_tax() )
$description = term_description( '', get_query_var( 'taxonomy' ) );
}

/* Format the meta description. */
if ( !empty( $description ) )
$description = '<meta name="description" content="' . str_replace( array( "\r", "\n", "\t" ), '', esc_attr( strip_tags( $description ) ) ) . '" />' . "\n";

echo apply_atomic( 'meta_description', $description );
}

/**
* Generates meta keywords/tags for the site. Checks theme settings.
* Checks indexing settings. Customize with the hybrid_meta_keywords filter.
*
* @since 0.2.3
*/
function hybrid_meta_keywords() {
global $wp_query;

$keywords = '';

/* If on a single post, check for custom field key Keywords and taxonomies. */
if ( is_singular() && !is_preview() ) {
$keywords = get_post_meta( $wp_query->post->ID, 'Keywords', true );

if ( empty( $keywords ) ) {
$taxonomies = get_object_taxonomies( $wp_query->post->post_type );

if ( is_array( $taxonomies ) ) {
foreach ( $taxonomies as $tax ) {
if ( $terms = get_the_term_list( $wp_query->post->ID, $tax, '', ', ', '' ) )
$keywords[] = $terms;
}
}

if ( !empty( $keywords ) )
$keywords = join( ', ', $keywords );
}
}

/* If we have keywords, join them together into one string and format for output. */
if ( !empty( $keywords ) )
$keywords = '<meta name="keywords" content="' . esc_attr( strip_tags( $keywords ) ) . '" />' . "\n";

echo apply_atomic( 'meta_keywords', $keywords );
}

?>
14 changes: 14 additions & 0 deletions functions/defaults.php
Expand Up @@ -297,4 +297,18 @@ function hybrid_disable_styles() {
wp_deregister_style( 'wp-pagenavi' );
}

/**
* Checks for a user-uploaded favicon in the child theme's /images folder. If it
* exists, display the <link> element for it.
*
* @since 0.4
*/
function hybrid_favicon() {
$favicon = '';

if ( file_exists( CHILD_THEME_DIR . '/images/favicon.ico' ) )
$favicon = '<link rel="shortcut icon" type="image/x-icon" href="' . CHILD_THEME_URI . '/images/favicon.ico" />' . "\n";
echo apply_atomic( 'favicon', $favicon );
}

?>

0 comments on commit e674efb

Please sign in to comment.