Skip to content

Instantly share code, notes, and snippets.

@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 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 / Custom Dashboard Widget - Side
Created March 22, 2013 04:51
Add Custom Dashboard Widget - Side - In Wordpress
//Add Custom Dashboard Widget - Side
add_action( 'wp_dashboard_setup', 'my_dashboard_setup_function' );
function my_dashboard_setup_function() {
add_meta_box( 'my_dashboard_widget', 'Electrico Useful Information', 'my_dashboard_widget_function', 'dashboard', 'side', 'high' );
}
function my_dashboard_widget_function() {
// widget content goes here
echo '<p>Some Content</p>';
}
@spencejs
spencejs / Custom Taxonomy Column.php
Last active December 15, 2015 06:49
Add Custom Taxonomy Admin Column In Wordpress
////////////////////////////////////////////////
//Add Project Type Column to Projects Backend
///////////////////////////////////////////////
add_filter('manage_edit-project_columns', 'project_columns');
function project_columns($columns) {
unset($columns['date']);
$columns['Type'] = 'Type';
$columns['date'] = 'Date';
return $columns;
}
@spencejs
spencejs / Customizable Additional Excerpt
Created March 22, 2013 04:46
Customizable Additional Excerpt In Wordpress ( USAGE: limit_content( $length, $allow-tags, '$tags-to-allow' ) )
//Custom Additional Excerpt Length
function custom_excerpt($content_length = 250, $allowtags = true, $allowedtags = '') {
global $post;
$exc = $post->post_excerpt;
if ($exc == '') {
$content = $post->post_content;
} else {
$content = $post->post_excerpt;
}
$content = apply_filters('the_content', $content);
@spencejs
spencejs / Custom Title Field Text
Created March 22, 2013 04:44
Custom Title Field Text By Post Type In Wordpress
//Change Title By Post Type
function custom_title_text( $title ){
$screen = get_current_screen();
if ( 'issues' == $screen->post_type ) {
$title = 'Issue Months and Year e.g. "Jul/Aug 2011"';
}
return $title;
}
add_filter( 'enter_title_here', 'custom_title_text' );
@spencejs
spencejs / Change Excerpt Length
Created March 22, 2013 04:34
Change Excerpt Length In Wordpress
//Change Excerpt Length
function new_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');
@spencejs
spencejs / Caption For Featured Image
Created March 22, 2013 04:04
Caption For Featured Image In Wordpress
@spencejs
spencejs / Add Alert Notice To Options Pages
Created March 22, 2013 03:57
Add Alert Notice To Options Pages In Wordpress
//Add Alert Notice To Options Pages
add_action( 'admin_notices', 'my_admin_notice' );
function my_admin_notice(){
global $current_screen;</div>
if ( $current_screen->parent_base == 'options-general' )
echo '<div><p>Warning - changing settings on these pages may cause problems with your website’s design!</p></div>';
}
@spencejs
spencejs / Include Tags In Search
Created March 22, 2013 03:53
Include Tags In Wordpress Search