Want more features on Pastebin? Sign Up, it's FREE!
Guest

functions.php - Underscores theme (custom for Margins)

By: a guest on Jan 16th, 2013  |  syntax: PHP  |  size: 5.48 KB  |  views: 34  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /**
  3.  * Margins functions and definitions
  4.  *
  5.  * @package Margins
  6.  * @since Margins 1.0
  7.  */
  8.  
  9. /**
  10.  * Set the content width based on the theme's design and stylesheet.
  11.  *
  12.  * @since Margins 1.0
  13.  */
  14. if ( ! isset( $content_width ) )
  15.         $content_width = 640; /* pixels */
  16.  
  17. if ( ! function_exists( 'tdm_setup' ) ) :
  18. /**
  19.  * Sets up theme defaults and registers support for various WordPress features.
  20.  *
  21.  * Note that this function is hooked into the after_setup_theme hook, which runs
  22.  * before the init hook. The init hook is too late for some features, such as indicating
  23.  * support post thumbnails.
  24.  *
  25.  * @since Margins 1.0
  26.  */
  27. function tdm_setup() {
  28.  
  29.         /**
  30.          * Custom template tags for this theme.
  31.          */
  32.         require( get_template_directory() . '/inc/template-tags.php' );
  33.  
  34.         /**
  35.          * Custom functions that act independently of the theme templates
  36.          */
  37.         require( get_template_directory() . '/inc/extras.php' );
  38.  
  39.         /**
  40.          * Custom Theme Options
  41.          */
  42.         //require( get_template_directory() . '/inc/theme-options/theme-options.php' );
  43.  
  44.         /**
  45.          * Make theme available for translation
  46.          * Translations can be filed in the /languages/ directory
  47.          * If you're building a theme based on Margins, use a find and replace
  48.          * to change 'tdm' to the name of your theme in all the template files
  49.          */
  50.         load_theme_textdomain( 'tdm', get_template_directory() . '/languages' );
  51.  
  52.         /**
  53.          * Add default posts and comments RSS feed links to head
  54.          */
  55.         add_theme_support( 'automatic-feed-links' );
  56.  
  57.         /**
  58.          * Enable support for Post Thumbnails
  59.          */
  60.         add_theme_support( 'post-thumbnails' );
  61.  
  62.         /**
  63.          * This theme uses wp_nav_menu() in one location.
  64.          */
  65.         register_nav_menus( array(
  66.                 'primary' => __( 'Primary Menu', 'tdm' ),
  67.         ) );
  68.  
  69.         /**
  70.          * Add support for the Aside Post Formats
  71.          */
  72.         add_theme_support( 'post-formats', array( 'aside', ) );
  73. }
  74. endif; // tdm_setup
  75. add_action( 'after_setup_theme', 'tdm_setup' );
  76.  
  77. /**
  78.  * Register widgetized area and update sidebar with default widgets
  79.  *
  80.  * @since Margins 1.0
  81.  */
  82. function tdm_widgets_init() {
  83.         register_sidebar( array(
  84.                 'name' => __( 'Home Meta Sidebar', 'tdm' ),
  85.                 'id' => 'sidebar-1',
  86.                 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  87.                 'after_widget' => '</aside>',
  88.                 'before_title' => '<h1 class="widget-title">',
  89.                 'after_title' => '</h1>',
  90.         ) );
  91.        
  92.         register_sidebar( array(
  93.                 'name' => __( 'Home Sidebar', 'tdm' ),
  94.                 'id' => 'sidebar-2',
  95.                 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  96.                 'after_widget' => '</aside>',
  97.                 'before_title' => '<h1 class="widget-title">',
  98.                 'after_title' => '</h1>',
  99.         ) );
  100. }
  101. add_action( 'widgets_init', 'tdm_widgets_init' );
  102.  
  103. /**
  104.  * Enqueue scripts and styles
  105.  */
  106. function tdm_scripts() {
  107.         wp_enqueue_style( 'style', get_stylesheet_uri() );
  108.  
  109.         wp_enqueue_script( 'libraries', get_template_directory_uri() . '/js/libraries-min.js', 'jquery', false);
  110.  
  111.         wp_enqueue_script( 'scripts', get_template_directory_uri() . '/js/scripts-min.js', array( 'jquery' ), '20120206', true );
  112.  
  113.         if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  114.                 wp_enqueue_script( 'comment-reply' );
  115.         }
  116.  
  117. }
  118. add_action( 'wp_enqueue_scripts', 'tdm_scripts' );
  119.  
  120. // Put post thumbnails into rss feed
  121. function tdm_feed_post_thumbnail($content) {
  122.         global $post;
  123.         if(has_post_thumbnail($post->ID)) {
  124.                 $content = '' . $content;
  125.         }
  126.         return $content;
  127. }
  128. add_filter('the_excerpt_rss', 'tdm_feed_post_thumbnail');
  129. add_filter('the_content_feed', 'tdm_feed_post_thumbnail');
  130.  
  131.  
  132. //create a permalink after the excerpt
  133. function tdm_replace_excerpt($content) {
  134.         return str_replace('[...]',
  135.                 '<a class="readmore" href="'. get_permalink() .'">...</a>',
  136.                 $content
  137.         );
  138. }
  139. add_filter('the_excerpt', 'tdm_replace_excerpt');
  140.  
  141.  
  142. // Stop images getting wrapped up in p tags when they get dumped out with the_content() for easier theme styling
  143. function tdm_remove_img_ptags($content){
  144.         return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
  145. }
  146. add_filter('the_content', 'tdm_remove_img_ptags');
  147.  
  148.  
  149. // Call the google CDN version of jQuery for the frontend
  150. // Make sure you use this with wp_enqueue_script('jquery'); in your header
  151. function tdm_jquery_enqueue() {
  152.         wp_deregister_script('jquery');
  153.         wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js", false, null);
  154.         wp_enqueue_script('jquery');
  155. }
  156. if (!is_admin()) add_action("wp_enqueue_scripts", "tdm_jquery_enqueue", 11);
  157.  
  158.  
  159. // Remove the version number of WP
  160. // Warning - this info is also available in the readme.html file in your root directory - delete this file!
  161. remove_action('wp_head', 'wp_generator');
  162.  
  163.  
  164. // Obscure login screen error messages
  165. function tdm_login_obscure(){ return '<strong>Sorry</strong>: Think you have gone wrong somewhere!';}
  166. add_filter( 'login_errors', 'tdm_login_obscure' );
  167.  
  168. /**
  169.  * Implement the Custom Header feature
  170.  */
  171. require( get_template_directory() . '/inc/custom-header.php' );
  172.  
  173. /**
  174.  *      Inserting into the hook of the header only in Home the featured post (latest)
  175.  *      Work on this at some point... Uncomment...
  176.  */
  177.  
  178.         function feature_post(){
  179.        
  180.                 if ( is_home() ){
  181.                        
  182.                          if ( have_posts() ) {
  183.                                 $featured = new WP_Query( 'posts_per_page=1' );
  184.                                  while ( $featured->have_posts() ) : $featured->the_post(){
  185.                                  
  186.                                         get_template_part( 'content', get_post_format() );
  187.                                        
  188.                                
  189.                                 }endwhile;
  190.                                                
  191.                         }
  192.                 add_action('feature_post','before_header');
  193.                 }
  194.         }
clone this paste RAW Paste Data