Created
October 18, 2015 16:33
-
-
Save Rhymes2k/d5a40af8892cdcc1b5cd to your computer and use it in GitHub Desktop.
Wordpress: Boilerplate Functions.php
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
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* Faster than @import | |
* | |
* http://codex.wordpress.org/Customizing_the_Login_Form | |
* | |
*/ | |
function my_child_theme_scripts() { | |
wp_enqueue_style( 'parent-theme-css', get_template_directory_uri() . '/style.css' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'my_child_theme_scripts' ); | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* Customize Favicon | |
* | |
* http://codex.wordpress.org/Customizing_the_Login_Form | |
* | |
*/ | |
// Custom Function to Include | |
function favicon_link() { | |
echo '<link rel="shortcut icon" type="image/x-icon" href="' . get_stylesheet_directory() .'/favicons/favicon.ico" />' . "\n"; | |
} | |
add_action( 'wp_head', 'favicon_link' ); | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* Title: Remove Black Baar on mobile | |
* | |
* http://codex.wordpress.org/Roles_and_Capabilities#Subscriber | |
* http://docs.appthemes.com/tutorials/wordpress-check-user-role-function/ | |
* | |
* @param string $role Role name. | |
* @param int $user_id (Optional) The ID of a user. Defaults to the current user. | |
* @return bool | |
*/ | |
if (!current_user_can('edit_posts') || wp_is_mobile() ) { | |
show_admin_bar(false); | |
} | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* TITLE: Change admin e-mail to new users | |
* DESCRIPTION: auto-detect the server so you only have to enter the front/from | |
* half of the email address, including the @ sign | |
* | |
* http://snipplr.com/view/77687/wordpress-change-admin-email-to-new-users/ | |
* http://miloguide.com/filter-hooks/wp_mail_from_name/ | |
* http://premium.wpmudev.org/blog/wordpress-email-settings/ | |
* | |
*/ | |
function admin_email_filter_wp_mail_from($email){ | |
/* start of code lifted from wordpress core, at | |
http://svn.automattic.com/wordpress/tags/3.4/wp-includes/pluggable.php */ | |
$sitename = strtolower( $_SERVER['SERVER_NAME'] ); | |
if ( substr( $sitename, 0, 4 ) == 'www.' ) { | |
$sitename = substr( $sitename, 4 ); | |
} | |
/* end of code lifted from wordpress core */ | |
$myfront = "noreply@"; | |
$myback = $sitename; | |
$myfrom = $myfront . $myback; | |
return $myfrom; | |
} | |
add_filter("wp_mail_from", "admin_email_filter_wp_mail_from"); | |
/** | |
* TITLE: Change admin name to new users | |
* DESCRIPTION: enter the full name you want displayed alongside the email address | |
* | |
* http://miloguide.com/filter-hooks/wp_mail_from_name/ | |
*/ | |
function admin_name_filter_wp_mail_from_name($from_name){ | |
return "GuitarPick"; | |
} | |
add_filter("wp_mail_from_name", "admin_name_filter_wp_mail_from_name"); | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* TITLE: Beautify the Log-in Page | |
* DESCRIPTION: Make the Log-in Page PRetty | |
* 1: Change out Logo | |
* 2: Change out URL | |
* 3: Change out Title | |
* | |
* http://codex.wordpress.org/Customizing_the_Login_Form | |
*/ | |
function my_login_logo() { ?> | |
<style type="text/css"> | |
body.login div#login h1 a { | |
background-image: none; | |
} | |
</style> | |
<?php } | |
add_action( 'login_enqueue_scripts', 'my_login_logo' ); | |
function my_login_logo_url() { | |
return home_url(); | |
} | |
add_filter( 'login_headerurl', 'my_login_logo_url' ); | |
function my_login_logo_url_title() { | |
return 'GuitarPick'; | |
} | |
add_filter( 'login_headertitle', 'my_login_logo_url_title' ); | |
function no_errors_please(){ | |
return 'Please Try Again'; | |
} | |
add_filter( 'login_errors', 'no_errors_please' ); | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* TITLE: Remove unnecessary meta-data from your WordPress site | |
* DESCRIPTION: Over the years, wordpress has placed a lot of junk in their system. | |
*/ | |
function remove_header_extra(){ | |
//Are you editing your WordPress blog using your browser? Then you are not using a blog client | |
remove_action('wp_head', 'rsd_link'); | |
// Windows Live Writer is (it�s another blog editing client | |
remove_action('wp_head', 'wlwmanifest_link'); | |
//This announces that you are running WordPress and what version you are using. | |
remove_action('wp_head', 'wp_generator'); | |
//URL shortening is sometimes useful, but this automatic ugly url in your header is useless. | |
remove_action('wp_head', 'wp_shortlink_wp_head'); | |
// Display the links to the general feeds: Post and Comment Feed | |
remove_action('wp_head', 'feed_links', 2); | |
//// Display the links to the extra feeds such as category feeds | |
remove_action('wp_head', 'feed_links_extra', 3); | |
//Deprecated | |
remove_action('wp_head', 'index_rel_link'); | |
// start link | |
remove_action('wp_head', 'start_post_rel_link', 10, 0); | |
// prev link | |
remove_action('wp_head', 'parent_post_rel_link', 10, 0); | |
// Display relational links for the posts adjacent to the current post. | |
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); | |
} | |
add_action('init', 'remove_header_extra'); | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* Title: Wordpress Dashboard | |
* Description: Remove all those boxes on the Wordpress Dashboard | |
* | |
* http://codex.wordpress.org/Function_Reference/remove_meta_box | |
*/ | |
function remove_dashboard_meta() { | |
remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); | |
remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' ); | |
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_welcome_panel', 'dashboard', 'normal' ); | |
} | |
add_action( 'admin_init', 'remove_dashboard_meta' ); | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* Title: Limit The Excerpt�s Word Count | |
* | |
* http://www.smashingmagazine.com/2011/12/07/10-tips-optimize-wordpress-theme/ | |
* | |
* | |
*/ | |
function ilc_excerpt_length( $length ){ | |
return 10; | |
} | |
add_filter('excerpt_length', 'ilc_excerpt_length'); | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* Title: Remove Black Baar on mobile | |
* | |
* http://codex.wordpress.org/Roles_and_Capabilities#Subscriber | |
* http://docs.appthemes.com/tutorials/wordpress-check-user-role-function/ | |
* | |
* @param string $role Role name. | |
* @param int $user_id (Optional) The ID of a user. Defaults to the current user. | |
* @return bool | |
*/ | |
if (!current_user_can('edit_posts') || wp_is_mobile() ) { | |
show_admin_bar(false); | |
} | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* Title: Redirect Wordpress Feeds to Feedburner | |
* | |
* http://www.smashingmagazine.com/2011/12/07/10-tips-optimize-wordpress-theme/ | |
*/ | |
function feed_to_feedburner_redirect() { | |
if ( is_feed() && !preg_match('/feedburner|feedvalidator/i', $_SERVER['HTTP_USER_AGENT'])){ | |
header('Location: http://feeds.feedburner.com/[THE_NAME_OF_YOUR_FEED]'); | |
header('HTTP/1.1 302 Temporary Redirect'); | |
} | |
} | |
//add_action('template_redirect', 'feed_to_feedburner_redirect'); | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* Title: Remove fields from woocommerce checkout | |
* | |
* [Override Billing](https://gist.github.com/mikejolley/1860056) | |
* [WooCommerce Plug-ins and hacks](http://wordpress.org/support/topic/woocommerce-remove-fields-on-edit-address) | |
* | |
*/ | |
// Our hooked in function - $fields is passed via the filter! | |
function custom_override_checkout_fields( $fields ) { | |
unset($fields['order']['order_comments']); | |
unset($fields['billing']['billing_phone']); | |
unset($fields['billing']['billing_address_2']); | |
unset($fields['billing']['billing_company']); | |
unset($fields['shipping']['shipping_company']); | |
unset($fields['shipping']['shipping_address_2']); | |
return $fields; | |
} | |
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' ); | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* Title: Make Woocommerce Phone Field Not Required | |
* | |
* [Override Billing](https://gist.github.com/mikejolley/1860056) | |
* [WooCommerce Plug-ins and hacks](http://wordpress.org/support/topic/woocommerce-remove-fields-on-edit-address) | |
* | |
*/ | |
function wc_npr_filter_phone( $address_fields ) { | |
$address_fields['billing_phone']['required'] = false; | |
return $address_fields; | |
} | |
add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 ); | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* Title: Show Featured Images In Feed | |
* | |
* http://www.smashingmagazine.com/2011/12/07/10-tips-optimize-wordpress-theme/ | |
* | |
* | |
*/ | |
function rss_post_thumbnail($content) { | |
global $post; | |
if( has_post_thumbnail($post->ID) ) | |
$content = '<p>' . get_the_post_thumbnail($post->ID, 'thumbnail') . '</p>' . $content; | |
return $content; | |
} | |
add_filter('the_content_feed', 'rss_post_thumbnail'); | |
/** ******** ******** ******** ******** ******** ******** ******** ******** | |
* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment