How to create a Page alias in WordPress

Those are actually post states; not aliases.. And you can do it through the display_post_states filter, like so, where we check if the post ID ($post->ID) is 123 and if so, we assign the XYZ Page state to that post (which could be a Page, Custom Post Type, etc.):

add_filter( 'display_post_states', 'my_post_states', 10, 2 );
function my_post_states( $post_states, $post ) {
    if ( 123 === $post->ID ) {
        $post_states['xyz_page'] = 'XYZ Page';
    }

    return $post_states;
}

And for reference, this is the conditional which WordPress uses for the “Front Page” and “Posts Page” states:

if ( 'page' === get_option( 'show_on_front' ) ) {
    if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) {
        $post_states['page_on_front'] = __( 'Front Page' );
    }

    if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) {
        $post_states['page_for_posts'] = __( 'Posts Page' );
    }
}

Leave a Comment