Skip to content

Instantly share code, notes, and snippets.

@offensivelyaverage
Created October 20, 2012 15:50
Show Gist options
  • Save offensivelyaverage/3923681 to your computer and use it in GitHub Desktop.
Save offensivelyaverage/3923681 to your computer and use it in GitHub Desktop.
functions.php
<?php
/**
* @package WordPress
* @subpackage themename
*/
/**
* Add jQuery
*/
function add_jquery_script() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', '', '1.7.2', true);
wp_enqueue_script( 'jquery' );
}
add_action('wp_enqueue_scripts', 'add_jquery_script');
// Re-define meta box path and URL
define( 'RWMB_URL', trailingslashit( get_stylesheet_directory_uri().'/includes/classes/meta-box' ) );
define( 'RWMB_DIR', trailingslashit( get_stylesheet_directory().'/includes/classes/meta-box' ) );
// Include the meta box script
require_once RWMB_DIR.'meta-box.php';
// Include the meta box definition (This is the file where you define meta boxes, see `demo/demo.php`)
include get_stylesheet_directory().'/includes/meta-box-config.php';
/**
* Make theme available for translation
* Translations can be filed in the /languages/ directory
*/
load_theme_textdomain( 'themename', get_template_directory() . '/languages' );
$locale = get_locale();
$locale_file = get_template_directory() . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
require_once( $locale_file );
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) )
$content_width = 640;
/**
* Remove code from the <head>
*/
//remove_action('wp_head', 'rsd_link'); // Might be necessary if you or other people on this site use remote editors.
//remove_action('wp_head', 'feed_links', 2); // Display the links to the general feeds: Post and Comment Feed
//remove_action('wp_head', 'feed_links_extra', 3); // Display the links to the extra feeds such as category feeds
//remove_action('wp_head', 'index_rel_link'); // Displays relations link for site index
//remove_action('wp_head', 'wlwmanifest_link'); // Might be necessary if you or other people on this site use Windows Live Writer.
//remove_action('wp_head', 'start_post_rel_link', 10, 0); // Start link
//remove_action('wp_head', 'parent_post_rel_link', 10, 0); // Prev link
//remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); // Display relational links for the posts adjacent to the current post.
remove_filter( 'the_content', 'capital_P_dangit' ); // Get outta my Wordpress codez dangit!
remove_filter( 'the_title', 'capital_P_dangit' );
remove_filter( 'comment_text', 'capital_P_dangit' );
// Hide the version of WordPress you're running from source and RSS feed // Want to JUST remove it from the source? Try: remove_action('wp_head', 'wp_generator');
/*function hcwp_remove_version() {return '';}
add_filter('the_generator', 'hcwp_remove_version');*/
// This function removes the comment inline css
/*function twentyten_remove_recent_comments_style() {
global $wp_widget_factory;
remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
}
add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );*/
add_theme_support( 'post-thumbnails' );
/**
* Remove meta boxes from Post and Page Screens
*/
function customize_meta_boxes() {
/* These remove meta boxes from POSTS */
//remove_post_type_support("post","excerpt"); //Remove Excerpt Support
//remove_post_type_support("post","author"); //Remove Author Support
//remove_post_type_support("post","revisions"); //Remove Revision Support
//remove_post_type_support("post","comments"); //Remove Comments Support
//remove_post_type_support("post","trackbacks"); //Remove trackbacks Support
//remove_post_type_support("post","editor"); //Remove Editor Support
//remove_post_type_support("post","custom-fields"); //Remove custom-fields Support
//remove_post_type_support("post","title"); //Remove Title Support
/* These remove meta boxes from PAGES */
//remove_post_type_support("page","revisions"); //Remove Revision Support
//remove_post_type_support("page","comments"); //Remove Comments Support
//remove_post_type_support("page","author"); //Remove Author Support
//remove_post_type_support("page","trackbacks"); //Remove trackbacks Support
//remove_post_type_support("page","custom-fields"); //Remove custom-fields Support
}
add_action('admin_init','customize_meta_boxes');
/**
* This theme uses wp_nav_menus() for the header menu, utility menu and footer menu.
*/
register_nav_menus( array(
'primary' => __( 'Big Icon Thing', 'themename' ),
//'secondary' => __( 'Right of header thing', 'themename' ),
'banner' => __( 'Banner thing', 'themename' ),
'overbanner' => __( 'Over Banner thing', 'themename' ),
'footer' => __( 'Footer Menu', 'themename' )
//'utility' => __( 'Utility Menu', 'themename' )
) );
/**
* Add default posts and comments RSS feed links to head
*/
add_theme_support( 'automatic-feed-links' );
/**
* This theme uses post thumbnails
*/
add_theme_support( 'post-thumbnails' );
/**
* This theme supports editor styles
*/
add_editor_style("/css/layout-style.css");
/**
* Remove superfluous elements from the admin bar (uncomment as necessary)
*/
function remove_admin_bar_links() {
global $wp_admin_bar;
//$wp_admin_bar->remove_menu('wp-logo');
//$wp_admin_bar->remove_menu('updates');
//$wp_admin_bar->remove_menu('my-account');
//$wp_admin_bar->remove_menu('site-name');
//$wp_admin_bar->remove_menu('my-sites');
//$wp_admin_bar->remove_menu('get-shortlink');
//$wp_admin_bar->remove_menu('edit');
//$wp_admin_bar->remove_menu('new-content');
//$wp_admin_bar->remove_menu('comments');
//$wp_admin_bar->remove_menu('search');
}
//add_action('wp_before_admin_bar_render', 'remove_admin_bar_links');
/**
* Replace the default welcome 'Howdy' in the admin bar with something more professional.
*/
function admin_bar_replace_howdy($wp_admin_bar) {
$account = $wp_admin_bar->get_node('my-account');
$replace = str_replace('Howdy,', 'Welcome,', $account->title);
$wp_admin_bar->add_node(array('id' => 'my-account', 'title' => $replace));
}
add_filter('admin_bar_menu', 'admin_bar_replace_howdy', 25);
/**
* This enables post formats. If you use this, make sure to delete any that you aren't going to use.
*/
//add_theme_support( 'post-formats', array( 'aside', 'audio', 'image', 'video', 'gallery', 'chat', 'link', 'quote', 'status' ) );
/**
* Register widgetized area and update sidebar with default widgets
*/
function handcraftedwp_widgets_init() {
register_sidebar( array (
'name' => __( 'Sidebar', 'themename' ),
'id' => 'sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s" role="complementary">',
'after_widget' => "</aside>",
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => __( 'Above Comments', 'themename' ),
'id' => 'above-commments',
'description' => __( 'Above the comments', 'themename' ),
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => '</li>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action( 'init', 'handcraftedwp_widgets_init' );
/*
* Remove senseless dashboard widgets for non-admins. (Un)Comment or delete as you wish.
*/
function remove_dashboard_widgets() {
global $wp_meta_boxes;
//unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); // Plugins widget
//unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); // WordPress Blog widget
//unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); // Other WordPress News widget
//unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); // Right Now widget
//unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); // Quick Press widget
//unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); // Incoming Links widget
//unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); // Recent Drafts widget
//unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); // Recent Comments widget
}
/**
* Hide Menu Items in Admin
*/
function themename_configure_dashboard_menu() {
global $menu,$submenu;
global $current_user;
get_currentuserinfo();
// $menu and $submenu will return all menu and submenu list in admin panel
// $menu[2] = ""; // Dashboard
// $menu[5] = ""; // Posts
// $menu[15] = ""; // Links
// $menu[25] = ""; // Comments
// $menu[65] = ""; // Plugins
// unset($submenu['themes.php'][5]); // Themes
// unset($submenu['themes.php'][12]); // Editor
}
// For non-admins, add action to Hide Dashboard Widgets and Admin Menu Items you just set above
// Don't forget to comment out the admin check to see that changes :)
if (!current_user_can('manage_options')) {
add_action('wp_dashboard_setup', 'remove_dashboard_widgets'); // Add action to hide dashboard widgets
add_action('admin_head', 'themename_configure_dashboard_menu'); // Add action to hide admin menu items
}
// samvtran: Adding an Ubuntu Web Store shortcode [web_store]
function web_store_shortcode($attrs, $content) {
extract(shortcode_atts(array(
'title' => '',
'url' => 'http://omgubuntu.co.uk'), $attrs));
return '<a class="ubuntu-software-center-link" href="'.esc_attr($url).'" title="'.esc_attr($title).'">'.$content.'</a>';
}
add_shortcode('web_store', 'web_store_shortcode');
?>
<?php // asynchronous google analytics: mathiasbynens.be/notes/async-analytics-snippet
// change the UA-XXXXX-X to be your site's ID
/*add_action('wp_footer', 'async_google_analytics');
function async_google_analytics() { ?>
<script>
var _gaq = [['_setAccount', 'UA-XXXXX-X'], ['_trackPageview']];
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.async = true;
g.src = ('https:' == location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
s.parentNode.insertBefore(g, s);
})(document, 'script');
</script>
<?php }*/ ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment