Skip to content

Instantly share code, notes, and snippets.

@Steven-Rose
Steven-Rose / gist:1728857
Created February 3, 2012 08:00
MySQL: Update from another table
UPDATE from_table t1, to_table t2
SET t2.field_name = t1.field_name
WHERE t2.field = t1.field
@Steven-Rose
Steven-Rose / gist:1728846
Created February 3, 2012 07:55
Canonical redirect to non-www
# canonical redirect to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
@Steven-Rose
Steven-Rose / gist:1728801
Created February 3, 2012 07:42
WP: Update all permalinks
UPDATE wp_options SET option_value = replace(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'http://olddomain.com', 'http://newdomain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://olddomain.com', 'http://newdomain.com');
@Steven-Rose
Steven-Rose / gist:1728796
Created February 3, 2012 07:40
WP: Child posts referencing meta value
$pages = get_pages('child_of='.$post->ID.'&meta_key=key&meta_value=value&sort_column=menu_order');
@Steven-Rose
Steven-Rose / gist:1728787
Created February 3, 2012 07:35
WP: Query for current author ID
/**
* Query DB for current author ID
*
* @global class $wpdb Global WordPress Database class
* @param String $author Author name from URL, identical to user_nicename in users table
* @return String User ID of author
*/
function get_author_id( $author ) {
global $wpdb;
$author_id = $wpdb->get_results( "SELECT `ID` from $wpdb->users u WHERE u.`user_nicename` = '$author'" );
@Steven-Rose
Steven-Rose / gist:1728775
Created February 3, 2012 07:32
WP: Set theme image sizes
add_theme_support( 'post-thumbnails' );
add_theme_support( 'page-thumbnails' );
set_post_thumbnail_size( 320, 240, true ); // Normal post thumbnails
add_image_size( 'list-display-thumbnail', 300, 225, true ); // Permalink thumbnail size
add_image_size( 'main-display-thumbnail', 660, 300, true ); // Permalink thumbnail size
add_image_size( 'tiny-display-thumbnail', 100, 60, true ); // Permalink thumbnail size
add_image_size( 'training-small-thumbnail', 235, 150, true ); // Permalink thumbnail size
add_image_size( 'blog-small-thumbnail', 150, 150, true ); // Permalink thumbnail size for blog
add_image_size( 'secondary-image-clients-thumbnail', 660, 300, true);
@Steven-Rose
Steven-Rose / gist:1728768
Created February 3, 2012 07:29
WP: Remove extra contact methods from user info
function remove_contact_methods( $contact_methods ) {
unset($contact_methods['yim']); // Remove Yahoo IM
unset($contact_methods['aim']); // Remove AIM
unset($contact_methods['jabber']); // Remove Jabber
return $contact_methods;
}
add_filter('user_contactmethods','remove_contact_methods',10,1);
@Steven-Rose
Steven-Rose / gist:1728766
Created February 3, 2012 07:29
WP: Custom admin favicon/logo
add_action('admin_head', 'custom_logo');
function custom_logo() {
echo '<style type="text/css">
#header-logo { background-image: url('.get_bloginfo('template_directory').'/favicon.ico) !important; }
</style>';
}
add_action('login_head', 'custom_login_logo');
function custom_login_logo() {
echo '<style type="text/css">
@Steven-Rose
Steven-Rose / gist:1728760
Created February 3, 2012 07:27
WP: Disable default link addition when inserting image into post
update_option('image_default_link_type' , 'none');
@Steven-Rose
Steven-Rose / gist:1728753
Created February 3, 2012 07:26
WP: Remove header info (potential for SEO path issues)
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feedremove_action( 'wp_head', 'start_post_rel_link'); // Removes the start link
remove_action( 'wp_head', 'start_post_rel_link'); // Removes the start link
remove_action( 'wp_head', 'wp_shortlink_wp_head' ); // Removes shortlink reference
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version