<?php
/**
* Margins functions and definitions
*
* @package Margins
* @since Margins 1.0
*/
/**
* Set the content width based on the theme's design and stylesheet.
*
* @since Margins 1.0
*/
if ( ! isset( $content_width ) )
$content_width = 640; /* pixels */
if ( ! function_exists( 'tdm_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which runs
* before the init hook. The init hook is too late for some features, such as indicating
* support post thumbnails.
*
* @since Margins 1.0
*/
function tdm_setup() {
/**
* Custom template tags for this theme.
*/
require( get_template_directory() . '/inc/template-tags.php' );
/**
* Custom functions that act independently of the theme templates
*/
require( get_template_directory() . '/inc/extras.php' );
/**
* Custom Theme Options
*/
//require( get_template_directory() . '/inc/theme-options/theme-options.php' );
/**
* Make theme available for translation
* Translations can be filed in the /languages/ directory
* If you're building a theme based on Margins, use a find and replace
* to change 'tdm' to the name of your theme in all the template files
*/
load_theme_textdomain( 'tdm', get_template_directory() . '/languages' );
/**
* Add default posts and comments RSS feed links to head
*/
add_theme_support( 'automatic-feed-links' );
/**
* Enable support for Post Thumbnails
*/
add_theme_support( 'post-thumbnails' );
/**
* This theme uses wp_nav_menu() in one location.
*/
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'tdm' ),
) );
/**
* Add support for the Aside Post Formats
*/
add_theme_support( 'post-formats', array( 'aside', ) );
}
endif; // tdm_setup
add_action( 'after_setup_theme', 'tdm_setup' );
/**
* Register widgetized area and update sidebar with default widgets
*
* @since Margins 1.0
*/
function tdm_widgets_init() {
register_sidebar( array(
'name' => __( 'Home Meta Sidebar', 'tdm' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Home Sidebar', 'tdm' ),
'id' => 'sidebar-2',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
}
add_action( 'widgets_init', 'tdm_widgets_init' );
/**
* Enqueue scripts and styles
*/
function tdm_scripts() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
wp_enqueue_script( 'libraries', get_template_directory_uri() . '/js/libraries-min.js', 'jquery', false);
wp_enqueue_script( 'scripts', get_template_directory_uri() . '/js/scripts-min.js', array( 'jquery' ), '20120206', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'tdm_scripts' );
// Put post thumbnails into rss feed
function tdm_feed_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'tdm_feed_post_thumbnail');
add_filter('the_content_feed', 'tdm_feed_post_thumbnail');
//create a permalink after the excerpt
function tdm_replace_excerpt($content) {
return str_replace('[...]',
'<a class="readmore" href="'. get_permalink() .'">...</a>',
$content
);
}
add_filter('the_excerpt', 'tdm_replace_excerpt');
// Stop images getting wrapped up in p tags when they get dumped out with the_content() for easier theme styling
function tdm_remove_img_ptags($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'tdm_remove_img_ptags');
// Call the google CDN version of jQuery for the frontend
// Make sure you use this with wp_enqueue_script('jquery'); in your header
function tdm_jquery_enqueue() {
wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js", false, null);
wp_enqueue_script('jquery');
}
if (!is_admin()) add_action("wp_enqueue_scripts", "tdm_jquery_enqueue", 11);
// Remove the version number of WP
// Warning - this info is also available in the readme.html file in your root directory - delete this file!
remove_action('wp_head', 'wp_generator');
// Obscure login screen error messages
function tdm_login_obscure(){ return '<strong>Sorry</strong>: Think you have gone wrong somewhere!';}
add_filter( 'login_errors', 'tdm_login_obscure' );
/**
* Implement the Custom Header feature
*/
require( get_template_directory() . '/inc/custom-header.php' );
/**
* Inserting into the hook of the header only in Home the featured post (latest)
* Work on this at some point... Uncomment...
*/
function feature_post(){
if ( is_home() ){
if ( have_posts() ) {
$featured = new WP_Query( 'posts_per_page=1' );
while ( $featured->have_posts() ) : $featured->the_post(){
get_template_part( 'content', get_post_format() );
}endwhile;
}
add_action('feature_post','before_header');
}
}