Skip to content

Instantly share code, notes, and snippets.

@spencejs
spencejs / Admin Alert
Created March 22, 2013 03:23
Add Alert to Wordpress Admin
//New User Alert
add_action( 'admin_notices', 'custom_error_notice' );
function custom_error_notice(){
global $current_user;
get_currentuserinfo();
$author_info = get_userdata($current_user->ID);
if($author_info->title == '')
echo '<div class="error"><p><strong>New User:</strong> Please visit your <a href="'.get_bloginfo('wpurl').'/wp-admin/profile.php" title="Your Profile">Profile</a> to Fill in your Job Title and set your Display Name. This alert will go away when you Job Title is set.</p></div>';
}
@spencejs
spencejs / Right Now Box
Created March 22, 2013 03:27
Add all custom post types and taxonomies to the "Right Now" box on the Wordpress Dashboard
// Add all custom post types and taxonomies to the "Right Now" box on the Dashboard
add_action( 'right_now_content_table_end' , 'ucc_right_now_content_table_end' );
function ucc_right_now_content_table_end() {
$args = array(
'public' => true ,
'_builtin' => false
);
$output = 'object';
$operator = 'and';
@spencejs
spencejs / Categories As Body Class Names
Created March 22, 2013 03:29
Add Categories For a Post As Class Names On The Body Tag - Wordpress
// add category nicenames in body and post class
function category_id_class($classes) {
global $post;
foreach((get_the_category($post->ID)) as $category)
$classes[] = $category->category_nicename;
return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');
@spencejs
spencejs / Custom Meta Value Column
Last active December 15, 2015 06:49
Add Column With A Custom Field To Wordpress Admin Post Listing
///////////////////////////////////////////////////////////
//Custom Backend Column from Custom Field. Be sure to edit post-type- "manage_edit-POSTTYPE_columns"- and Custom Field Name.
///////////////////////////////////////////////////////////
add_filter('manage_edit-staff_columns', 'my_columns');
function my_columns($columns) {
unset($columns['author']);
unset($columns['date']);
$columns['Name'] = 'Name';
$columns['author'] = 'Author';
$columns['date'] = 'Date';
@spencejs
spencejs / Add Custom Post type To Feed
Created March 22, 2013 03:34
Add Custom Post Type To Main Wordpress Feed
//Add Custom Post Type To Feed
function mysite_feed_request($vars) {
if (isset($vars['feed']) && !isset($vars['post_type']))
$vars['post_type'] = array('post', 'projects');
return $vars;
}
add_filter('request', 'mysite_feed_request');
@spencejs
spencejs / Featured Image Instructions
Created March 22, 2013 03:35
Add Instruction Text To Featured Image Box In Wordpress Admin
@spencejs
spencejs / Meta Boxes Without A Plugin
Created March 22, 2013 03:38
Add Wordpress Meta Boxes Without A Plugin
/**
Made with the help of a tutorial at WPShout.com => http://wpshout.com.
Courtesy of the Hybrid theme - themehybrid.com
* Adds the Hybrid Settings meta box on the Write Post/Page screeens
*
* @package Hybrid
* @subpackage Admin
*/
@spencejs
spencejs / Add Post Thumbnails
Created March 22, 2013 03:39
Add Post Thumbnails To Wordpress
add_theme_support('post-thumbnails');
set_post_thumbnail_size( 150, 120, true ); // Normal post thumbnails
add_image_size( 'magazine-post-thumbnail', 260, 174, true ); // Permalink thumbnail size
add_image_size( 'home-post-thumbnail', 168, 89, true ); // Permalink thumbnail size
add_image_size( 'single-post-thumbnail', 527, 317, true ); // Permalink thumbnail size
@spencejs
spencejs / Add Post Thumbnail to Feed
Created March 22, 2013 03:42
Add Post Thumbnail to Feed in Wordpress
//Add Post Thumbnail to Feed
function feedFilter($query) {
if ($query->is_feed) {
add_filter('the_content', 'feedContentFilter');
}
return $query;
}
add_filter('pre_get_posts','feedFilter');
function feedContentFilter($content) {
@spencejs
spencejs / Add Post Type To Category Archives
Created March 22, 2013 03:43
Add Post Type To Category Archives In Wordpress
// Add Post Type To Category Archives
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('nav_menu_item','post','private_post'); // replace private_post to your custom post type, Leave nav_menu_item where it is!
$query->set('post_type',$post_type);