Code snipits

11.09.10Made on the Gold Coast 1 Response

Add these to your functions.php inside your theme

Disable Pingbacks – Source


add_filter( ‘xmlrpc_methods’, function( $methods ) {
   unset( $methods['pingback.ping'] );
   return $methods;
} );

Maintenance mode without plug-in – source


function maintenace_mode() {
    if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {wp_die('Maintenance.');}
}
add_action('get_header', 'maintenace_mode');

Using shortcodes to show members-only content – source


add_shortcode( 'visitor', 'visitor_check_shortcode' );
function visitor_check_shortcode( $atts, $content = null ) {
  if ( ( !is_user_logged_in() && !is_null( $content ) ) || is_feed() )
  return $content;
  return '';
}


add_shortcode( 'member', 'member_check_shortcode' );
function member_check_shortcode( $atts, $content = null ) {
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
  return $content;
  return '';
}

Search only posts – source


/* Search only posts */
function SearchFilter($query) {

  if ($query->is_search) {
      $query->set('post_type', 'post');
  }
  
  return $query;

}
add_filter('pre_get_posts','SearchFilter');

Adjust jpeg quality – source


function gpp_jpeg_quality_callback($arg) {

    return (int)100; // change 100 to whatever you prefer, but don't go below 60

}
add_filter('jpeg_quality', 'gpp_jpeg_quality_callback');

Add an excerpt box for pages

/*Add an excerpt box for pages*/


if ( function_exists('add_post_type_support') ){

  add_action('init', 'add_page_excerpts');
  
  function add_page_excerpts(){
  
    add_post_type_support( 'page', 'excerpt' );

  }
}

Customise your admin footer

/*change admin footer*/


function remove_footer_admin () {

  echo 'Fueled by <a href="&quot;http://www.wordpress.org&quot;" target="&quot;_blank&quot;">WordPress</a> | Designed by <a href="&quot;http://thriveweb.com.au/&quot;" target="&quot;_blank&quot;">thrive</a>';

}
add_filter('admin_footer_text', 'remove_footer_admin');

Define your own login logo – source

/*Define your own login logo*/


function my_custom_login_logo() {

  echo 'h1 a { background-image:url('.get_bloginfo('template_directory').'/images/logo.png) !important;}';

}

add_action('login_head', 'my_custom_login_logo');
add_filter( 'login_headerurl', 'w4_login_headerurl');

function w4_login_headerurl(){

  return home_url('/');

}

Hide the Themes menu item.

/*Remove theme menus*/


add_action('admin_init', 'remove_theme_menus');

function remove_theme_menus() {

  global $submenu;
  
  unset($submenu['themes.php'][5]);
  
  unset($submenu['themes.php'][15]);

}

Add a favicon to your admin area


// add a favicon for your admin
function admin_favicon() {

  echo '<link href="&quot;'.get_bloginfo('stylesheet_directory').'/favicon.png&quot;" rel="&quot;Shortcut" type="&quot;image/x-icon&quot;" />';

}

add_action('admin_head', 'admin_favicon');

Remove unused menu items – source


function remove_menus () {

  global $menu;
  
  $restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
  
  end ($menu);
  
  while (prev($menu)){
  
    $value = explode(' ',$menu[key($menu)][0]);
    
    if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
    
  }

}

add_action('admin_menu', 'remove_menus');


<strong>Remove admin tool bar - <a href="http://designwoop.com/2011/03/how-to-remove-the-wordpress-admin-bar/">source</a></strong>

//Remove admin tool bar
function my_function_admin_bar(){
  return 0;
}

add_filter( 'show_admin_bar' , 'my_function_admin_bar');

Limit the max upload size – source


add_filter('wp_handle_upload_prefilter', function($file) {
  
  $size = $file['size'];
  
  if ($size &gt; 500 * 1024) {
  
  $file['error'] = '"Files larger than X bytes are prevented from uploads.';
  
  }
  
  return $file;

});

1 Comments

  1. Thanks for the great read, Glad to see all of these culminated on one post. great reference, Will definitely utilize on my client sites.

Leave a Reply

site5

More from our labs!

psr2

A responsive WordPress gallery plugin

pinzolo-t

A free responsive WordPress theme

bannerspace2

A WordPress banner / slideshow plugin

cf7

Pure CSS to Style Contact Form 7

ps2

WordPress gallery plugin