Skip to content

Instantly share code, notes, and snippets.

@spencejs
spencejs / Remove Specific Dashboard Widgets
Created March 22, 2013 05:45
Remove Specific Dashboard Widgets From Wordpress
add_action( 'admin_menu', 'remove_dashboard_boxes' );
function remove_dashboard_boxes() {
remove_meta_box( 'dashboard_right_now', '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' );
}
@spencejs
spencejs / Deregister Categories Taxonomy
Created March 22, 2013 05:43
Deregister Categories Taxonomy In Wordpress
//Deregister Categories Taxonomy
add_action( 'init', 'unregister_taxonomy');
function unregister_taxonomy(){
global $wp_taxonomies;
$taxonomy = 'category';
if ( taxonomy_exists( $taxonomy))
unset( $wp_taxonomies[$taxonomy]);
}
@spencejs
spencejs / Remove Admin Menu Items
Created March 22, 2013 05:38
Remove Admin Menu Items In Wordpress
//Remove Admin Menu Items
function remove_menu_items() {
global $menu;
$restricted = array(__('Links'), __('Posts'));
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){
unset($menu[key($menu)]);}
}
@spencejs
spencejs / Move Featured Image Box by Post Type
Created March 22, 2013 05:37
Move Featured Image Box by Post Type In Wordpress
//Move Featured Image Box by Post Type
add_action('do_meta_boxes', 'customposttype_image_box');
function customposttype_image_box() {
remove_meta_box( 'postimagediv', 'art', 'side' );
add_meta_box('postimagediv', __('Custom Image'), 'post_thumbnail_meta_box', 'art', 'normal', 'high');
}
@spencejs
spencejs / Make Tags or Category Pages Query Custom Post Types
Created March 22, 2013 05:34
Make Tags or Category Pages Query Custom Post Types In Wordpress
//Make Tags or Category Pages Query Custom Post Types
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('projects'); // replace cpt to your custom post type
@spencejs
spencejs / Hide Admin Bar Except For Administrators
Created March 22, 2013 05:32
Hide Admin Bar Except For Administrators In Wordpress
//Hide Admin Bar Except For Administrators
function my_function_admin_bar($content) {
return ( current_user_can("administrator") ) ? $content : false;
}
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
@spencejs
spencejs / Force Post Type To Be Private
Created March 22, 2013 05:19
Force Post Type To Be Private In Wordpress
//Force Post type to be Private
function force_type_private($post){
if ($post['post_type'] == 'my_post_type')
$post['post_status'] = 'private';
return $post;
}
add_filter('wp_insert_post_data', 'force_type_private');
@spencejs
spencejs / Exclude Categories From The Feed
Created March 22, 2013 05:16
Exclude Categories From The Feed In Wordpress
//Exclude Categories From The Feed
function myFeedExcluder($query) {
if ($query->is_feed) {
$query->set('cat','-178,-9');
}
return $query;
}
add_filter('pre_get_posts','myFeedExcluder');
@spencejs
spencejs / Customize Admin Footer
Created March 22, 2013 05:12
Customize Wordpress Admin Footer Text
@spencejs
spencejs / Custom Elements For TinyMCE
Created March 22, 2013 05:05
Custom Elements For TinyMCE In Wordpress
//Custom Elements For TinyMCE
// add style selector drop down
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
// add styles - more info: http://alisothegeek.com/2011/05/tinymce-styles-dropdown-wordpress-visual-editor/