Created
July 22, 2014 01:10
-
-
Save alenabdula/233407f88e3dea0336d0 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* ---------------------------------------- | |
* Adds template name, as class, on the body | |
* @return Array | |
* ---------------------------------------- | |
*/ | |
add_filter('body_class', 'the_fresh_class_themer'); | |
function the_fresh_class_themer($classes = '') | |
{ | |
global $template; | |
$classes[] = substr(basename($template), 0, -4); | |
return $classes; | |
} | |
/** | |
* ---------------------------------------- | |
* Displays, front-end, which template is being used | |
* @return String | |
* ---------------------------------------- | |
*/ | |
add_action( 'wp_head', 'init_template_display' ); | |
function init_template_display() | |
{ | |
if ( current_user_can('manage_options') ) { | |
global $template; | |
echo '<div class="cf" style="padding:24px;text-align:center;"><b>Using Template, <em>init_template_display();</em><br></b><code>'.$template.'</code></div>'; | |
} | |
} | |
/** | |
* ---------------------------------------- | |
* Displays all WordPress Constants defined | |
* @return String | |
* ---------------------------------------- | |
*/ | |
add_action( 'wp_head', 'init_display_all_constants' ); | |
function init_display_all_constants() | |
{ | |
if ( current_user_can('manage_options') ) { | |
echo '<div class="cf" style="padding:24px;text-align:center;"><b>All Defined Constants</b>'; | |
var_dump(@get_defined_constants()); | |
echo '</div>'; | |
} | |
} | |
/** | |
* ---------------------------------------- | |
* Theme Clean Up | |
* ---------------------------------------- | |
*/ | |
add_action('init', 'init_theme_clean_up'); | |
function init_theme_clean_up() | |
{ | |
remove_action( 'wp_head', 'feed_links_extra', 3 ); | |
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_wp_head', 10, 0 ); | |
remove_action( 'wp_head', 'wp_generator' ); | |
add_filter( 'show_admin_bar', '__return_false' ); | |
} | |
/** | |
* ---------------------------------------- | |
* Theme Support | |
* ---------------------------------------- | |
*/ | |
add_action( 'after_setup_theme', 'init_theme_support' ); | |
function init_theme_support() | |
{ | |
add_post_type_support('page', ['excerpt']); | |
add_theme_support('automatic-feed-links'); | |
add_theme_support('post-formats', [ | |
'aside', | |
'gallery', | |
'link', | |
'image', | |
'quote', | |
'status', | |
'video', | |
'audio', | |
'chat' | |
]); | |
add_theme_support('menus'); | |
register_nav_menu('head-navigation', __( 'Header Navigation')); | |
register_nav_menu('side-navigation', __( 'Sidebar Navigation')); | |
register_nav_menu('foot-navigation', __( 'Footer Navigation')); | |
add_theme_support('post-thumbnails'); | |
set_post_thumbnail_size(125, 125, true); | |
add_image_size('brand-300', 300, 100, true ); | |
add_theme_support('custom-background'); | |
add_theme_support('html5', ['search-form', 'comment-form', 'comment-list']); | |
} | |
/** | |
* ---------------------------------------- | |
* Nicely Formatted Title | |
* @return String | |
* ---------------------------------------- | |
*/ | |
add_filter( 'wp_title', 'init_nicely_formatted_titles', 10, 2 ); | |
function init_nicely_formatted_titles( $title, $sep ) | |
{ | |
global $paged, $page; | |
if ( is_feed() ) { return $title; } | |
$title .= get_bloginfo( 'name' ); | |
$site_description = get_bloginfo( 'description', 'display' ); | |
if ( $site_description && ( is_home() || is_front_page() ) ) { | |
$title = "$title $sep $site_description"; | |
} | |
if ( $paged >= 2 || $page >= 2 ) { | |
$title = "$title $sep " . sprintf( __( 'Page %s' ), max( $paged, $page ) ); | |
} | |
return $title; | |
} | |
/** | |
* ---------------------------------------- | |
* Clear Administration Panel | |
* ---------------------------------------- | |
*/ | |
add_action( 'admin_menu', 'init_disable_dash_components' ); | |
function init_disable_dash_components() | |
{ | |
remove_meta_box( 'dashboard_right_now', 'dashboard', 'core' ); | |
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'core' ); | |
remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'core' ); | |
remove_meta_box( 'dashboard_plugins', 'dashboard', 'core' ); | |
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'core' ); | |
remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'core' ); | |
remove_meta_box( 'dashboard_primary', 'dashboard', 'core' ); | |
remove_meta_box( 'dashboard_secondary', 'dashboard', 'core' ); | |
} | |
/** | |
* ---------------------------------------- | |
* Remove dimensions from images, responsive images | |
* @return String | |
* ---------------------------------------- | |
*/ | |
add_filter( 'post_thumbnail_html', 'init_remove_wh_responsive_images', 10 ); | |
add_filter( 'image_send_to_editor', 'init_remove_wh_responsive_images', 10 ); | |
function init_remove_wh_responsive_images($html) | |
{ | |
return preg_replace( '/(width|height)=\"\d*\"\s/', "", $html ); | |
} | |
/** | |
* ---------------------------------------- | |
* Load Administration Scripts & Styles | |
* ---------------------------------------- | |
*/ | |
add_action('admin_head', 'init_admin_scripts_styles'); | |
function init_admin_scripts_styles() | |
{ | |
wp_enqueue_style( 'admin', get_template_directory_uri() . '/css/admin.min.css', [], '1.0', 'all' ); | |
} | |
/** | |
* ---------------------------------------- | |
* Front-End Scripts & Styles | |
* ---------------------------------------- | |
*/ | |
add_action( 'wp_enqueue_scripts', 'init_theme_scripts_styles' ); | |
function init_theme_scripts_styles() | |
{ | |
global $wp_styles; | |
# scripts | |
wp_enqueue_script( 'jquery' ); | |
# wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); | |
wp_enqueue_script( 'main', get_template_directory_uri() . '/js/master.min.js', ['jquery'], '1.0', true ); | |
# styles | |
# wp_enqueue_style( $handle, $src, $deps, $ver, $media ); | |
wp_enqueue_style( 'main', get_template_directory_uri() . '/css/master.min.css', [], '1.0', 'all' ); | |
} | |
/** | |
* ---------------------------------------- | |
* Turn current_* to active classes on wp_nav_menu() | |
* @return String | |
* ---------------------------------------- | |
*/ | |
add_filter ('wp_nav_menu','init_change_current_nav_classes'); | |
function init_change_current_nav_classes($text) | |
{ | |
$replace = [ | |
'current_page_item' => 'active', | |
'current_page_parent' => 'active', | |
'current_page_ancestor' => 'active', | |
]; | |
return str_replace(array_keys($replace), $replace, $text); | |
} | |
/** | |
* ---------------------------------------- | |
* Custom Administration Footer Credit | |
* @return String | |
* ---------------------------------------- | |
*/ | |
add_filter('admin_footer_text', 'init_custom_footer_info'); | |
function init_custom_footer_info() | |
{ | |
echo '<a href="http://alenabdula.com/" target="_blank">Alen Abdula</a>'; | |
} | |
/** | |
* ---------------------------------------- | |
* Remove Top-Left WordPress Logo | |
* ---------------------------------------- | |
*/ | |
add_action('wp_before_admin_bar_render', 'init_remove_top_left_wp_logo', 0); | |
function init_remove_top_left_wp_logo() | |
{ | |
global $wp_admin_bar; | |
$wp_admin_bar->remove_menu('wp-logo'); | |
} | |
/** | |
* ---------------------------------------- | |
* Widgets | |
* ---------------------------------------- | |
*/ | |
add_action( 'widgets_init', 'init_theme_widgets' ); | |
function init_theme_widgets() | |
{ | |
register_sidebar([ | |
'name' => __( 'Sidebar One'), | |
'id' => 'sidebar-1', | |
'description' => __('Sidebar One allows you to include widgets!'), | |
'before_widget' => '<div id="%1$s" class="widget %2$s">', | |
'after_widget' => '</div>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2>', | |
]); | |
register_sidebar([ | |
'name' => __( 'Sidebar Two'), | |
'id' => 'sidebar-2', | |
'description' => __('Sidebar Two allows you to include widgets!'), | |
'before_widget' => '<div id="%1$s" class="widget %2$s">', | |
'after_widget' => '</div>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2>', | |
]); | |
} | |
/** | |
* ---------------------------------------- | |
* Remove Menu Items | |
* ---------------------------------------- | |
*/ | |
add_action('admin_menu', 'init_remove_admin_menu_items', 102); | |
function init_remove_admin_menu_items() | |
{ | |
global $submenu; | |
$remove_menu_page_collection = [ | |
// 'index.php', // Dashboard | |
// 'edit.php', // Posts | |
// 'upload.php', // Media | |
// 'edit.php?post_type=page', // Pages | |
// 'edit-comments.php', // Comments | |
// 'themes.php', // Appearance | |
// 'plugins.php', // Plugins | |
// 'users.php', // Users | |
// 'tools.php', // Tools | |
// 'options-general.php', // Settings | |
// 'edit.php?post_type=acf', // Advanced Custom Fields | |
]; | |
foreach ($remove_menu_page_collection as $collection) { | |
# remove_menu_page( $menu-slug ); | |
remove_menu_page($collection); | |
} | |
$remove_submenu_page_collection = [ | |
// 'themes.php' => 'theme-editor.php', | |
// 'index.php' => 'update-core.php', | |
]; | |
foreach ($remove_submenu_page_collection as $key => $value) { | |
# remove_submenu_page( $menu_slug, $submenu_slug ); | |
remove_submenu_page( $key, $value ); | |
} | |
} | |
/** | |
* ---------------------------------------- | |
* Unregistering Default Widgets | |
* ---------------------------------------- | |
*/ | |
add_action('widgets_init', 'init_unregister_default_widgets'); | |
function init_unregister_default_widgets() | |
{ | |
$widgets_collection = [ | |
'WP_Widget_Pages', | |
'WP_Widget_Calendar', | |
'WP_Widget_Archives', | |
'WP_Widget_Links', | |
'WP_Widget_Meta', | |
'WP_Widget_Search', | |
'WP_Widget_Text', | |
'WP_Widget_Categories', | |
'WP_Widget_Recent_Posts', | |
'WP_Widget_Recent_Comments', | |
'WP_Widget_RSS', | |
'WP_Widget_Tag_Cloud', | |
'WP_Nav_Menu_Widget', | |
'Twenty_Eleven_Ephemera_Widget', | |
]; | |
foreach ($widgets_collection as $item) { | |
unregister_widget($item); | |
} | |
} | |
/** | |
* ---------------------------------------- | |
* Custom Login | |
* @return String | |
* ---------------------------------------- | |
*/ | |
add_action('login_head', 'init_custom_login_branding'); | |
function init_custom_login_branding() | |
{ | |
$path = get_template_directory_uri() . '/img/wp_admin_login_branding.png'; | |
echo '<style>body{background-color:#dff0c8!important;}.login h1 a{background-image:url('.$path.')!important;background-size:125px 62px!important;width:125px!important;height:62px!important;}</style>'; | |
} | |
/** | |
* ---------------------------------------- | |
* Custom Login URL | |
* @return String | |
* ---------------------------------------- | |
*/ | |
add_filter( 'login_headerurl', 'init_custom_login_url' ); | |
function init_custom_login_url() | |
{ | |
return get_bloginfo('url', 'raw'); | |
} | |
/** | |
* ---------------------------------------- | |
* Custom Login Title | |
* @return String | |
* ---------------------------------------- | |
*/ | |
add_filter('login_headertitle', 'init_custom_login_title'); | |
function init_custom_login_title() | |
{ | |
return get_option('blogname'); | |
} | |
/** | |
* ---------------------------------------- | |
* Remove <p> around images | |
* see: http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/ | |
* @return String | |
* ---------------------------------------- | |
*/ | |
add_filter('the_content', 'init_remove_p_tags_around_images'); | |
function init_remove_p_tags_around_images($content) | |
{ | |
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment