Created
October 15, 2014 13:06
-
-
Save jbreitenbucher/c14b99bb88986348c683 to your computer and use it in GitHub Desktop.
Common WordPress custom functions
This file contains 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
/* Limit Your Website Excerpt */ | |
function word_limit($string, $max_words){ | |
$post_words = explode(' ', $string); | |
$count = count($post_words); | |
$post_words = implode(' ', array_slice($post_words, 0, $max_words)); | |
if($count > $max_words): | |
return $post_words . '...'; | |
else: | |
return $post_words; | |
endif; | |
} | |
// CUSTOM ADMIN MENU LINK FOR ALL SETTINGS | |
function all_settings_link() { | |
add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php'); | |
} | |
add_action('admin_menu', 'all_settings_link'); | |
/* Only See Own Attachments */ | |
add_action('pre_get_posts','users_attachments'); | |
function users_attachments( $wp_query_obj ) { | |
global $current_user, $pagenow; | |
if( !is_a( $current_user, 'WP_User') ) | |
return; | |
if( 'upload.php' != $pagenow ) | |
return; | |
if( !current_user_can('delete_pages') ) | |
$wp_query_obj->set('author', $current_user->id ); | |
return; | |
} | |
add_action( 'login_head', 'login_logo' ); | |
/** | |
* Replaces the login header logo | |
*/ | |
function login_logo() { | |
$image_attributes = wp_get_attachment_image_src( 1, 'full' ); | |
echo '<style> .login h1 a { background-image: url( ' . $image_attributes[0] . ' ) !important; }</style>'; | |
} | |
add_filter( 'login_headerurl', 'login_logo_headerurl' ); | |
/** | |
* Replaces the login header logo URL | |
* | |
* @param $url | |
*/ | |
function login_logo_headerurl( $url ) { | |
$url = home_url( '/' ); | |
return $url; | |
} | |
add_filter( 'login_headertitle', 'login_logo_headertitle' ); | |
/** | |
* Replaces the login header logo title | |
* | |
* @param $title | |
*/ | |
function login_logo_headertitle( $title ) { | |
$title = get_bloginfo( 'name' ); | |
return $title; | |
} | |
// REMOVE POST META BOXES | |
function remove_metaboxes() { | |
/* Posts */ | |
remove_meta_box( 'authordiv','post','normal' ); // Author Metabox | |
remove_meta_box( 'commentstatusdiv','post','normal' ); // Comments Status Metabox | |
remove_meta_box( 'commentsdiv','post','normal' ); // Comments Metabox | |
remove_meta_box( 'postcustom','post','normal' ); // Custom Fields Metabox | |
remove_meta_box( 'postexcerpt','post','normal' ); // Excerpt Metabox | |
remove_meta_box( 'revisionsdiv','post','normal' ); // Revisions Metabox | |
remove_meta_box( 'slugdiv','post','normal' ); // Slug Metabox | |
remove_meta_box( 'trackbacksdiv','post','normal' ); // Trackback Metabox | |
/* Pages */ | |
remove_meta_box( 'postcustom','page','normal' ); // Custom Fields Metabox | |
remove_meta_box( 'postexcerpt','page','normal' ); // Excerpt Metabox | |
remove_meta_box( 'commentstatusdiv','page','normal' ); // Comments Metabox | |
remove_meta_box( 'trackbacksdiv','page','normal' ); // Talkback Metabox | |
remove_meta_box( 'slugdiv','page','normal' ); // Slug Metabox | |
remove_meta_box( 'authordiv','page','normal' ); // Author Metabox | |
} | |
add_action('admin_menu', 'remove_metaboxes'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment