Snippet Category User Experience

Increase Search Results

function increase_search_results($query) {
    if ($query->is_search) {
        $query->set('posts_per_page', '50');
    }
    return $query;
}
add_filter('pre_get_posts', 'increase_search_results');

Redirect User After Login

function my_login_redirect($redirect_to, $request, $user) {
    //Is it an admin? If so, let them go to default place
    if (isset($user->roles) && is_array($user->roles) && in_array('administrator', $user->roles)) {
        return $redirect_to;
    } else {
        return home_url('your-url'); // Change URL
    }
}
add_filter('login_redirect', 'my_login_redirect', 10, 3);

Set Custom Excerpt Length

function custom_excerpt_length( $length ) {
    return 20; // Return 20 words
}
add_filter('excerpt_length', 'custom_excerpt_length');