Add custom post types to the recent posts widget

Adding custom post types to the recent posts widget is straightforward. WordPress has a built-in filter that can be used to adjust the query and adding parameters to include custom post types. In order to include our custom post types, we can use the post_type parameter and specify the posts types that we want to display in our recent posts widget.

The php code snippet below is to be inserted in your functions.php file to achieve just that.

PHP
function wph_login_logo_title( $params ) {
    $params['post_type'] = array( 'post','movie' );
    return $params;
}
add_filter( 'widget_posts_args', 'wph_login_logo_title' );

Once added just change the word ‘movie’ with your real custom post type name and voilà.

Please note that you can add more than one custom post type in the native recent posts widget if you want to. To do that you have to insert your custom post types names in an array separated by commas otherwise it won’t work for you.