Skip to content

Instantly share code, notes, and snippets.

@ovizii
ovizii / functions.php
Created April 10, 2014 15:26
Disable auto-linking in comments
remove_filter('comment_text', 'make_clickable', 9);
@ovizii
ovizii / functions.php
Created April 10, 2014 15:25
Login with email
function login_with_email_address($username) {
$user = get_user_by('email',$username);
if(!empty($user->user_login))
$username = $user->user_login;
return $username;
}
add_action('wp_authenticate','login_with_email_address');
function change_username_wps_text($text){
if(in_array($GLOBALS['pagenow'], array('wp-login.php'))){
@ovizii
ovizii / functions.php
Created April 10, 2014 15:24
Force scripts into wp_footer
if(!is_admin()){
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);
}
@ovizii
ovizii / functions.php
Created April 10, 2014 15:22
Force SSL/HTTPS on Specific Post IDs
function wps_force_ssl( $force_ssl, $post_id = 0, $url = '' ) {
if ( $post_id == 25 ) {
return true
}
return $force_ssl;
}
add_filter('force_ssl' , 'wps_force_ssl', 10, 3);
@ovizii
ovizii / functions.php
Created April 10, 2014 15:21
Show Post/Page IDs in backend
add_filter('manage_posts_columns', 'posts_columns_id', 5);
add_action('manage_posts_custom_column', 'posts_custom_id_columns', 5, 2);
add_filter('manage_pages_columns', 'posts_columns_id', 5);
add_action('manage_pages_custom_column', 'posts_custom_id_columns', 5, 2);
function posts_columns_id($defaults){
$defaults['wps_post_id'] = __('ID');
return $defaults;
}
@ovizii
ovizii / functions.php
Created April 10, 2014 15:20
Remove image sizes
update_option( 'thumbnail_size_h', 0 );
update_option( 'thumbnail_size_w', 0 );
update_option( 'medium_size_h', 0 );
update_option( 'medium_size_w', 0 );
update_option( 'large_size_h', 0 );
update_option( 'large_size_w', 0 );
@ovizii
ovizii / functions.php
Created April 10, 2014 15:19
Sharpen images when resizing
function ajx_sharpen_resized_files( $resized_file ) {
$image = wp_load_image( $resized_file );
if ( !is_resource( $image ) )
return new WP_Error( 'error_loading_image', $image, $file );
$size = @getimagesize( $resized_file );
if ( !$size )
return new WP_Error('invalid_image', __('Could not read image size'), $file);
list($orig_w, $orig_h, $orig_type) = $size;
@ovizii
ovizii / functions.php
Created April 10, 2014 15:19
Update WP Search Permalink URL
function fb_change_search_url_rewrite() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
exit();
}
}
add_action( 'template_redirect', 'fb_change_search_url_rewrite' );
@ovizii
ovizii / functions.php
Created April 10, 2014 15:18
Remove WordPress Version from Header
// remove version info from head and feeds
function complete_version_removal() {
return '';
}
add_filter('the_generator', 'complete_version_removal');
@ovizii
ovizii / functions.php
Created April 10, 2014 15:17
Require a Featured Post Image
//This code checks for a featured image when updating. If no image exists it will save the current draft without publishing, and display an error message to the writer. This will ensure that no post can go live without a featured image attached.
add_action('save_post', 'wpds_check_thumbnail');
add_action('admin_notices', 'wpds_thumbnail_error');
function wpds_check_thumbnail($post_id) {
// change to any custom post type
if(get_post_type($post_id) != 'post')
return;
if ( !has_post_thumbnail( $post_id ) ) {
// set a transient to show the users an admin message