Forked from yusn/gist:76d91a8befa70fb0187b2427de4f5a92
Last active
March 23, 2018 21:32
-
-
Save brentini/701aef66da35f0f1073f526db5980f90 to your computer and use it in GitHub Desktop.
A base for a functions.php for a WordPress theme #wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @package WordPress | |
| * @subpackage Theme_Name | |
| * @since Theme Name 1.0 | |
| */ | |
| // replace "themename" with the theme slug | |
| // load javascript on initialization | |
| add_action( 'init', 'themename_init' ); | |
| function themename_init() { | |
| if ( ! is_admin() ) { | |
| // use google hosted jquery | |
| wp_deregister_script( 'jquery' ); | |
| wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' ); | |
| wp_enqueue_script( 'jquery' ); | |
| // load any other scripts below | |
| } | |
| remove_action( 'wp_head', 'feed_links_extra', 3 ); | |
| remove_action( 'wp_head', 'feed_links', 2 ); | |
| remove_action( 'wp_head', 'rsd_link' ); | |
| remove_action( 'wp_head', 'wlwmanifest_link' ); | |
| remove_action( 'wp_head', 'index_rel_link' ); | |
| remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); | |
| remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); | |
| remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); | |
| remove_action( 'wp_head', 'wp_generator' ); | |
| add_filter( 'show_recent_comments_widget_style', '__return_false' ); | |
| } | |
| // add theme supports and nav menus | |
| add_action( 'after_setup_theme', 'themename_setup' ); | |
| function themename_setup() { | |
| add_theme_support( 'menus' ); | |
| add_theme_support( 'post-thumbnails' ); | |
| add_theme_support( 'automatic-feed-links' ); | |
| register_nav_menus( array( | |
| 'primary' => __( 'Primary Navigation', 'themename' ) | |
| // other nav menus here | |
| ) ); | |
| } | |
| // register widget areas | |
| add_action( 'widgets_init', 'themename_widgets_init', 1 ); | |
| function themename_widgets_init() { | |
| unregister_widget( 'WP_Widget_Pages' ); | |
| unregister_widget( 'WP_Widget_Calendar' ); | |
| //unregister_widget( 'WP_Widget_Archives' ); | |
| //unregister_widget( 'WP_Widget_Links' ); | |
| unregister_widget( 'WP_Widget_Meta' ); | |
| //unregister_widget( 'WP_Widget_Search' ); | |
| //unregister_widget( 'WP_Widget_Text' ); | |
| //unregister_widget( 'WP_Widget_Categories' ); | |
| //unregister_widget( 'WP_Widget_Recent_Posts' ); | |
| unregister_widget( 'WP_Widget_Recent_Comments' ); | |
| unregister_widget( 'WP_Widget_RSS' ); | |
| unregister_widget( 'WP_Widget_Tag_Cloud' ); | |
| register_sidebar( array( | |
| 'name' => __( 'Primary Widget Area', 'themename' ), | |
| 'id' => 'primary-widget-area', | |
| 'description' => __( 'The primary widget area on the left side', 'themename' ), | |
| 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', | |
| 'after_widget' => '</li>', | |
| 'before_title' => '<h3 class="widget-title">', | |
| 'after_title' => '</h3>', | |
| ) ); | |
| // other sidebars here | |
| } | |
| // build header information | |
| add_action( 'wp_head', 'themename_head' ); | |
| function themename_head() { | |
| // code here | |
| } | |
| // posted on structured used in twentyten | |
| function themename_posted_on() { | |
| printf( __( 'By %1$s <span class="meta-sep">|</span> %2$s', 'themename' ), | |
| sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>', | |
| get_author_posts_url( get_the_author_meta( 'ID' ) ), | |
| sprintf( esc_attr__( 'View all posts by %s', 'themename' ), get_the_author() ), | |
| get_the_author() | |
| ), | |
| sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>', | |
| get_permalink(), | |
| esc_attr( get_the_time() ), | |
| get_the_date() | |
| ) | |
| ); | |
| } | |
| // comment structure from twentyten | |
| function themename_comment( $comment, $args, $depth ) { | |
| $GLOBALS['comment'] = $comment; | |
| switch ( $comment->comment_type ) : | |
| case '' : | |
| ?> | |
| <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> | |
| <div id="comment-<?php comment_ID(); ?>"> | |
| <p class="commentmetadata"><?php printf( __( '%s', 'themename' ), get_comment_author_link() ); ?> | <?php printf( __( '%1$s at %2$s', 'themename' ), get_comment_date(), get_comment_time() ); ?></p> | |
| <?php if ( $comment->comment_approved == '0' ) : ?> | |
| <p><em><?php _e( 'Your comment is awaiting moderation.', 'themename' ); ?></em></p> | |
| <?php endif; ?> | |
| <div class="comment-body"><?php comment_text(); ?></div> | |
| <div class="reply"> | |
| <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> | |
| </div><!-- .reply --> | |
| </div><!-- #comment-## --> | |
| <?php | |
| break; | |
| case 'pingback' : | |
| case 'trackback' : | |
| ?> | |
| <li class="post pingback"> | |
| <p><?php _e( 'Pingback:', 'themename' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'themename'), ' ' ); ?></p> | |
| <?php | |
| break; | |
| endswitch; | |
| } | |
| // change default "read more" link | |
| function themename_continue_reading_link() { | |
| return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'themename' ) . '</a>'; | |
| } | |
| // change default [...] | |
| add_filter( 'excerpt_more', 'themename_auto_excerpt_more' ); | |
| function themename_auto_excerpt_more( $more ) { | |
| return ' …' . themename_continue_reading_link(); | |
| } | |
| // remove the gallery style that is automatically added | |
| add_filter( 'gallery_style', 'themename_remove_gallery_css' ); | |
| function themename_remove_gallery_css( $css ) { | |
| return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css ); | |
| } | |
| // remove update notifications for everybody except admin users | |
| global $user_login; | |
| get_currentuserinfo(); | |
| if ( ! current_user_can( 'update_plugins' ) ) { // checks to see if current user can update plugins | |
| add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); | |
| add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); | |
| } | |
| // remove dashboard boxes | |
| add_action( 'admin_menu', 'themename_remove_dashboard_boxes' ); | |
| function themename_remove_dashboard_boxes() { | |
| //remove_meta_box( 'dashboard_right_now', 'dashboard', 'core' ); // Right Now Overview Box | |
| //remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'core' ); // Incoming Links Box | |
| //remove_meta_box( 'dashboard_quick_press', 'dashboard', 'core' ); // Quick Press Box | |
| //remove_meta_box( 'dashboard_plugins', 'dashboard', 'core' ); // Plugins Box | |
| //remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'core' ); // Recent Drafts Box | |
| //remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'core' ); // Recent Comments | |
| remove_meta_box( 'dashboard_primary', 'dashboard', 'core' ); // WordPress Development Blog | |
| remove_meta_box( 'dashboard_secondary', 'dashboard', 'core' ); // Other WordPress News | |
| } | |
| // make TinyMCE allow iframes | |
| add_filter( 'tiny_mce_before_init', create_function( '$a', '$a["extended_valid_elements"] = "iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]"; return $a;' ) ); | |
| // add all custom post types to rss feed | |
| add_filter( 'request', 'themename_addtofeed_request' ); | |
| function themename_addtofeed_request( $qv ) { | |
| if ( isset( $qv['feed'] ) ) | |
| $qv['post_type'] = get_post_types(); | |
| return $qv; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment