0

So I have several CPTs set up but I want to have all my default posts listed under /blog.

I was hoping I could somehow enable has_archive for the default post type but I have yet to succeed.

Any ideas?

add_action( 'init', 'enhance_post' );

function enhance_post( ) {
    global $wp_post_types;

    $wp_post_types['post']->has_archive = true;
    $wp_post_types['post']->rewrite = array(
        'slug' => 'blog',
        'with_front' => 0,
        'pages' => 1,
    );
}

(the above doesn't seem to work)

0

You can change front page and designate another as blog via Reading settings.

See Creating a Static Front Page in Codex.

0

You can use the below code

add_action( 'init', function () {
    $post_type = 'post';
    $post_type_object = get_post_type_object( $post_type);
    $post_type_object->has_archive = 'true';
    $post_type_object->rewrite = array(
        'slug' => '<YOUR_SLUG>',
    );

    register_post_type($post_type, $post_type_object);
} );

and in addition to that, you can add rewrite rules to handle that :

add_rewrite_rule( '^<YOUR_SLUG>$','index.php?post_type=post','top' );
add_rewrite_rule( '^<YOUR_SLUG>/page/([0-9]{1,})/?$','index.php?post_type=post&paged=$matches[1]','top' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.