diff --git a/packages/editor/src/components/post-card-panel/index.js b/packages/editor/src/components/post-card-panel/index.js
index 1365659f70814..410b8cfd4447d 100644
--- a/packages/editor/src/components/post-card-panel/index.js
+++ b/packages/editor/src/components/post-card-panel/index.js
@@ -21,22 +21,17 @@ import {
} from '../../store/constants';
import { unlock } from '../../lock-unlock';
import PostActions from '../post-actions';
+import usePageTypeBadge from '../../utils/pageTypeBadge';
export default function PostCardPanel( {
postType,
postId,
onActionPerformed,
} ) {
- const { isFrontPage, isPostsPage, title, icon } = useSelect(
+ const { title, icon } = useSelect(
( select ) => {
const { __experimentalGetTemplateInfo } = select( editorStore );
- const { canUser, getEditedEntityRecord } = select( coreStore );
- const siteSettings = canUser( 'read', {
- kind: 'root',
- name: 'site',
- } )
- ? getEditedEntityRecord( 'root', 'site' )
- : undefined;
+ const { getEditedEntityRecord } = select( coreStore );
const _record = getEditedEntityRecord(
'postType',
postType,
@@ -51,12 +46,13 @@ export default function PostCardPanel( {
icon: unlock( select( editorStore ) ).getPostIcon( postType, {
area: _record?.area,
} ),
- isFrontPage: siteSettings?.page_on_front === postId,
- isPostsPage: siteSettings?.page_for_posts === postId,
};
},
[ postId, postType ]
);
+
+ const pageTypeBadge = usePageTypeBadge();
+
return (
{ title ? decodeEntities( title ) : __( 'No title' ) }
- { isFrontPage && (
-
- { __( 'Homepage' ) }
-
- ) }
- { isPostsPage && (
+ { pageTypeBadge && (
- { __( 'Posts Page' ) }
+ { pageTypeBadge }
) }
diff --git a/packages/editor/src/utils/pageTypeBadge.js b/packages/editor/src/utils/pageTypeBadge.js
new file mode 100644
index 0000000000000..321b9caa17769
--- /dev/null
+++ b/packages/editor/src/utils/pageTypeBadge.js
@@ -0,0 +1,41 @@
+/**
+ * WordPress dependencies
+ */
+import { __ } from '@wordpress/i18n';
+import { useSelect } from '@wordpress/data';
+import { store as coreStore } from '@wordpress/core-data';
+
+/**
+ * Internal dependencies
+ */
+import { store as editorStore } from '../store';
+
+/**
+ * Custom hook to get the page type badge for the current post on edit site view.
+ */
+export default function usePageTypeBadge() {
+ const { isFrontPage, isPostsPage } = useSelect( ( select ) => {
+ const { getCurrentPostId } = select( editorStore );
+ const { canUser, getEditedEntityRecord } = select( coreStore );
+ const postId = getCurrentPostId();
+ const siteSettings = canUser( 'read', {
+ kind: 'root',
+ name: 'site',
+ } )
+ ? getEditedEntityRecord( 'root', 'site' )
+ : undefined;
+
+ return {
+ isFrontPage: siteSettings?.page_on_front === postId,
+ isPostsPage: siteSettings?.page_for_posts === postId,
+ };
+ } );
+
+ if ( isFrontPage ) {
+ return __( 'Homepage' );
+ } else if ( isPostsPage ) {
+ return __( 'Posts Page' );
+ }
+
+ return false;
+}