Skip to content

Instantly share code, notes, and snippets.

View ataylorme's full-sized avatar

Andrew Taylor ataylorme

View GitHub Profile
@ataylorme
ataylorme / disallow-folder-in-virtual-robots
Last active October 12, 2015 22:58
Disallow folder in virtual robots.txt
function virtual_robots_disallow( $output, $public ) {
$output .= "\n" . 'Disallow: /backup' . "\n";
return $output;
}
add_filter( 'robots_txt', 'virtual_robots_disallow', 10, 2 );
@ataylorme
ataylorme / restrict-user-posts
Created November 17, 2012 22:46
Restrict user posts
/* ===== START RESTRICT USER POSTS ====== */
function restricted_posts_for_current_author($query) {
global $user_ID;
if($query->is_admin && $user_ID !== 10 )
$query->set('author', -10);
unset($user_level);
return $query;
}
add_filter('pre_get_posts', 'restricted_posts_for_current_author');
@ataylorme
ataylorme / enable-shortcodes-in-sidebar-widgets
Created November 17, 2012 22:46
Enable shortcodes in sidebar widgets
add_filter('widget_text', 'do_shortcode');
@ataylorme
ataylorme / get-taxonomy-of-current-archive-page
Created November 17, 2012 22:48
Get taxonomy of current archive page
<?php $currentTax = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
@ataylorme
ataylorme / is-subpage-function
Created November 17, 2012 22:50
Is subpage function
function is_subpage($pid) { // $pid = The ID of the page we're looking for pages underneath
global $post; // load details about this page
if(is_page()&&($post->post_parent==$pid||is_page($pid)))
return true; // we're at the page or at a sub page
else
return false; // we're elsewhere
}
@ataylorme
ataylorme / menu-walker-class
Created November 17, 2012 22:52
Menu Walker Class
class custom_menu_walker extends Walker_Nav_Menu{
function start_el(&$output, $item, $depth, $args){
global $wp_query;
$indent = ( $depth ) ? str_repeat( "t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
$ancestors = get_ancestors( $item->ID, 'page' );
@ataylorme
ataylorme / non-www-to-www-redirect
Created November 17, 2012 22:53
non-www to www redirect
RewriteCond %{HTTP_HOST} !^www.
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
@ataylorme
ataylorme / google-maps-link-by-address
Created November 17, 2012 22:55
Google maps link by address
@ataylorme
ataylorme / remove-all-enqueued-scripts-and-styles-for-a-custom-post-type
Created November 17, 2012 23:07
Remove all enqueue'd scripts and styles for a custom post type
/* ========== START REMOVE ALL ENQUEUED EXISTING SCRIPTS AND STYLEs ========== */
if( !function_exists('clean_wp_head') ):
function clean_wp_head(){
if( !function_exists('MY_CUSTOM_POST_TYPE_remove_all_scripts') ):
function MY_CUSTOM_POST_TYPE_remove_all_scripts() {
global $wp_scripts; $wp_scripts->queue = array();
}//end MY_CUSTOM_POST_TYPE_remove_all_scripts function
endif;
if( !function_exists('MY_CUSTOM_POST_TYPE_remove_all_styles') AND !is_admin() ):
function MY_CUSTOM_POST_TYPE_remove_all_styles() {
@ataylorme
ataylorme / remove-twentyeleven-theme-options-from-child-theme
Created November 17, 2012 23:08
Remove twentyeleven theme options from child theme
//Remove the custom options provided by the default twentyeleven theme.
add_action( 'after_setup_theme','remove_twentyeleven_options', 100 );
function remove_twentyeleven_options() {
remove_custom_background();
remove_custom_image_header();
remove_action('admin_menu', 'twentyeleven_theme_options_add_page');
}