Created
October 22, 2011 00:25
-
-
Save agustibr/1305334 to your computer and use it in GitHub Desktop.
WP Collection of Code for functions.php [1]
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 | |
// ADD CUSTOM POST TYPES TO THE 'RIGHT NOW' DASHBOARD WIDGET | |
function wph_right_now_content_table_end() { | |
$args = array( | |
'public' => true , | |
'_builtin' => false | |
); | |
$output = 'object'; | |
$operator = 'and'; | |
$post_types = get_post_types( $args , $output , $operator ); | |
foreach( $post_types as $post_type ) { | |
$num_posts = wp_count_posts( $post_type->name ); | |
$num = number_format_i18n( $num_posts->publish ); | |
$text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) ); | |
if ( current_user_can( 'edit_posts' ) ) { | |
$num = "<a href='edit.php?post_type=$post_type->name'>$num</a>"; | |
$text = "<a href='edit.php?post_type=$post_type->name'>$text</a>"; | |
} | |
echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>'; | |
echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>'; | |
} | |
$taxonomies = get_taxonomies( $args , $output , $operator ); | |
foreach( $taxonomies as $taxonomy ) { | |
$num_terms = wp_count_terms( $taxonomy->name ); | |
$num = number_format_i18n( $num_terms ); | |
$text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms )); | |
if ( current_user_can( 'manage_categories' ) ) { | |
$num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>"; | |
$text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>"; | |
} | |
echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>'; | |
echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>'; | |
} | |
} | |
add_action( 'right_now_content_table_end' , 'wph_right_now_content_table_end' ); |
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 | |
// CUSTOM ADMIN LOGIN HEADER LOGO | |
function my_custom_login_logo() { | |
echo '<style type="text/css"> h1 a { background-image:url('.get_bloginfo('template_directory').'/images/your-logo-image.png) !important; } </style>'; | |
} | |
add_action('login_head', 'my_custom_login_logo'); | |
// CUSTOM ADMIN LOGIN HEADER LINK & ALT TEXT | |
function change_wp_login_url() { | |
echo bloginfo('url'); // OR ECHO YOUR OWN URL | |
} | |
function change_wp_login_title() { | |
echo get_option('blogname'); // OR ECHO YOUR OWN ALT TEXT | |
} | |
add_filter('login_headerurl', 'change_wp_login_url'); | |
add_filter('login_headertitle', 'change_wp_login_title'); |
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 | |
// Remove default fields contact info user profile and replace them with something more usable | |
function update_contact_methods( $contactmethods ) { | |
// Remove annoying and unwanted default fields | |
unset($contactmethods['aim']); | |
unset($contactmethods['jabber']); | |
unset($contactmethods['yim']); | |
// Add new fields | |
$contactmethods['phone'] = 'Phone'; | |
$contactmethods['mobile'] = 'Mobile'; | |
$contactmethods['address'] = 'Address'; | |
return $contactmethods; | |
} | |
add_filter('user_contactmethods','update_contact_methods'); | |
/** | |
To display custom fields you can use one of the two methods listed below. | |
// Option 1: | |
the_author_meta('facebook', $current_author->ID) | |
// Option 2: | |
<?php $current_author = get_userdata(get_query_var('author')); ?> | |
<p><a href="<?php echo esc_url($current_author->contact_phone_office);?>" title="office_phone"> Office Phone</a></p> | |
**/ |
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 | |
function fb_disable_feed() { | |
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') ); | |
} | |
add_action('do_feed', 'fb_disable_feed', 1); | |
add_action('do_feed_rdf', 'fb_disable_feed', 1); | |
add_action('do_feed_rss', 'fb_disable_feed', 1); | |
add_action('do_feed_rss2', 'fb_disable_feed', 1); | |
add_action('do_feed_atom', 'fb_disable_feed', 1); |
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 | |
// even more smart jquery inclusion :) | |
add_action( 'init', 'jquery_register' ); | |
// register from google and for footer | |
function jquery_register() { | |
if ( !is_admin() ) { | |
wp_deregister_script( 'jquery' ); | |
wp_register_script( 'jquery', ( 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js' ), false, null, true ); | |
wp_enqueue_script( 'jquery' ); | |
} | |
} |
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 | |
/** | |
* Set the post revisions unless the constant was set in wp-config.php | |
* Default is infinite, this will set it to only remember last 5 edits: | |
*/ | |
if (!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS', 5); |
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 | |
// REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN | |
global $user_login; | |
get_currentuserinfo(); | |
if (!current_user_can('update_plugins')) { // checks to see if current user can update plugins | |
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); | |
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); | |
} |
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 | |
// MAKE CUSTOM POST TYPES SEARCHABLE | |
function searchAll( $query ) { | |
if ( $query->is_search ) { $query->set( 'post_type', array( 'site','plugin', 'theme','person' )); } | |
return $query; | |
} | |
add_filter( 'the_search_query', 'searchAll' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from http://wordpress.stackexchange.com/questions/1567/best-collection-of-code-for-your-functions-php-file