admin管理员组文章数量:1130349
In the image you see... WordPress has alias for Pages like Home Page, Checkout Page, Privacy Policy Page and any appear beside the page you assign them.
How to create this feature in WordPress? If I want to alias a page like XYZ Page and when I assign any page to that alias... XYZ Page appears beside the assigned page.
In the image you see... WordPress has alias for Pages like Home Page, Checkout Page, Privacy Policy Page and any appear beside the page you assign them.
How to create this feature in WordPress? If I want to alias a page like XYZ Page and when I assign any page to that alias... XYZ Page appears beside the assigned page.
Share Improve this question edited Oct 31, 2018 at 7:26 besrabasant asked Oct 31, 2018 at 3:22 besrabasantbesrabasant 1361 silver badge6 bronze badges1 Answer
Reset to default 2Those 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' );
}
}
In the image you see... WordPress has alias for Pages like Home Page, Checkout Page, Privacy Policy Page and any appear beside the page you assign them.
How to create this feature in WordPress? If I want to alias a page like XYZ Page and when I assign any page to that alias... XYZ Page appears beside the assigned page.
In the image you see... WordPress has alias for Pages like Home Page, Checkout Page, Privacy Policy Page and any appear beside the page you assign them.
How to create this feature in WordPress? If I want to alias a page like XYZ Page and when I assign any page to that alias... XYZ Page appears beside the assigned page.
Share Improve this question edited Oct 31, 2018 at 7:26 besrabasant asked Oct 31, 2018 at 3:22 besrabasantbesrabasant 1361 silver badge6 bronze badges1 Answer
Reset to default 2Those 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' );
}
}
本文标签: pluginsHow to create a Page alias in WordPress
版权声明:本文标题:plugins - How to create a Page alias in WordPress 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749218209a2334520.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论