Output which theme template file a post/page is using in the header
add_action('wp_head', 'show_template');
function show_template() {
global $template;
print_r($template);
}
Shorten the default DIV output if your theme is using post_class.
If your theme is using something like
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
You can have crazy long divs in your source that might look like this or even longer:
<div id="post-4" class="post-4 post type-post hentry category-uncategorized category-test category-test-1-billion category-test2 category-test3 category-testing">
This can really start to clutter your source and seem rather unnecessary in most cases, going 3-4 deep is good enough.
For the top example we can slice the output like so:
// Slice crazy long div outputs
function category_id_class($classes) {
global $post;
foreach((get_the_category($post->ID)) as $category)
$classes[] = $category->category_nicename;
return array_slice($classes, 0,5);
}
add_filter('post_class', 'category_id_class');
This slices the output to only include the first 5 values, so the above example becomes:
<div id="post-4" class="post-4 post type-post hentry category-uncategorized">
Make category archives display all posts, regardless of post type: good for custom post types
function any_ptype_on_cat($request) {
if ( isset($request['category_name']) )
$request['post_type'] = 'any';
return $request;
}
add_filter('request', 'any_ptype_on_cat');
Remove unwanted dashboard items
This was already posted but it did not have the full list of items. Especially those annoying "incoming links!"
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
// Right Now - Comments, Posts, Pages at a glance
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
// Recent Comments
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
// Incoming Links
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
// Plugins - Popular, New and Recently updated Wordpress Plugins
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
// WordPress Development Blog Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
// Other WordPress News Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
// Quick Press Form
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
// Recent Drafts List
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
}
Remove "Read More" page jumps**
Instead return to the top of the page. You know how when you click "read more" it will jump to the spot in the page which can be annoying, this makes it just load the page normally, no jumping!
function remove_more_jump_link($link) {
$offset = strpos($link, '#more-');
if ($offset) {
$end = strpos($link, '"', $offset);
}
if ($end) {
$link = substr_replace($link, '', $offset, $end-$offset);
}
return $link;
}
add_filter('the_content_more_link', 'remove_more_jump_link');
Restrict ADMIN menu items based on username, replace username with an actual user's name.
function remove_menus()
{
global $menu;
global $current_user;
get_currentuserinfo();
if($current_user->user_login == 'username')
{
$restricted = array(__('Posts'),
__('Media'),
__('Links'),
__('Pages'),
__('Comments'),
__('Appearance'),
__('Plugins'),
__('Users'),
__('Tools'),
__('Settings')
);
end ($menu);
while (prev($menu)) {
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL ? $value[0] : "" , $restricted)) {
unset($menu[key($menu)]);
}
} // end while
} // end if
}
add_action('admin_menu', 'remove_menus');
//alternatively you can use if($current_user->user_login != 'admin') instead, probably more useful
Style the tag cloud
// Tag cloud custom
add_filter('widget_tag_cloud_args', 'style_tags');
function style_tags($args) {
$args = array(
'largest' => '10',
'smallest' => '10',
'format' => 'list',
);
return $args;
}
A full reference of options are here (there are a lot!) http://codex.wordpress.org/Function_Reference/wp_tag_cloud
Change Default RSS Widget update timer
(The default is 6 or 12 hours - I forget (1800 = 30 minutes).
add_filter( 'wp_feed_cache_transient_lifetime', create_function('$fixrss', 'return 1800;') );