Skip to content

Instantly share code, notes, and snippets.

@spencejs
spencejs / Custom Login Stylesheet
Created March 22, 2013 04:55
Custom Stylesheet For Wordpress Login Page
//Custom Login Page
function custom_login() {
echo '<link rel="stylesheet" type="text/css" href="'.get_bloginfo('template_directory').'/custom-login/custom-login.css" />';
}
add_action('login_head', 'custom_login');
@spencejs
spencejs / Drafts Dashboard Widget For Custom Post Type
Created March 22, 2013 04:57
Drafts Dashboard Widget For Custom Post Type In Wordpress
//Drafts Dashboard Widget For Custom Post Type
function project_drafts(){
$posts_query = new WP_Query( array(
// Leave this as "post" if you just want blog posts
'post_type' => 'projects',
'post_status' => 'draft',
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'DESC'
) );
@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/
@spencejs
spencejs / Customize Admin Footer
Created March 22, 2013 05:12
Customize Wordpress Admin Footer Text
@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 / 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 / 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 / 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 / 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 / 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)]);}
}