// Display 2 products per page. Goes in functions.php
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 2;' ), 20 );
code snippets
woo change products per row
// Change number of products per row
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
function loop_columns() {
return 4; // 4 products per row
}
}
comment smackdown
// Disable comments and hide from admin menu and admin bar in functions.php
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
// Remove comments metabox from dashboard
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
// Disable support for comments and trackbacks in post types
foreach (get_post_types() as $post_type) {
if (post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
}
});
// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);
// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);
// Remove comments page in menu
add_action('admin_menu', function () {
remove_menu_page('edit-comments.php');
});
// Remove comments links from admin bar
add_action('init', function () {
if (is_admin_bar_showing()) {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}
});
remove woo ads
// Fix woo ads: add_filter('woocommerce_allow_marketplace_suggestions', '__return_false');
// Fix Jetpack ads: add_filter( 'jetpack_show_promotions', '__return_false', 20 );
change any text
// Change text strings http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
function my_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Related Products' :
$translated_text = __( 'Check out these related products', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );
hide admin notices
add_action(
'admin_head',
function() {
remove_action( 'admin_notices', 'update_nag', 3 );
}
);
turn off admin email check
// turn off admin email check
add_filter( 'admin_email_check_interval', '__return_false' );
change recovery mode email address
// change recovery mode email address.
add_filter( 'recovery_mode_email', function( $email_data ) {
$email_data['to'] = 'your_email@yoursite.com';
return $email_data;
});
Stop WordPress from wrapping images in paragraph tags
// Stop WordPress from wrapping images in paragraph tags.
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
first image as featured image if unset
// first image as featured image if unset
function auto_featured_image() {
global $post;
if (!has_post_thumbnail($post->ID)) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
}
}
}
// Use it temporary to generate all featured images
add_action('the_post', 'auto_featured_image');
// Used for new posts
add_action('save_post', 'auto_featured_image');
add_action('draft_to_publish', 'auto_featured_image');
add_action('new_to_publish', 'auto_featured_image');
add_action('pending_to_publish', 'auto_featured_image');
add_action('future_to_publish', 'auto_featured_image');