diff --git a/packages/editor/src/components/post-url/panel.js b/packages/editor/src/components/post-url/panel.js index 15804db6f30723..aca36566c04727 100644 --- a/packages/editor/src/components/post-url/panel.js +++ b/packages/editor/src/components/post-url/panel.js @@ -10,6 +10,7 @@ import { } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; import { safeDecodeURIComponent } from '@wordpress/url'; +import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies @@ -43,7 +44,7 @@ export default function PostURLPanel() { return ( - + { - const { getCurrentPost } = select( editorStore ); + const { slug, isFrontPage, postLink } = useSelect( ( select ) => { + const { getCurrentPostId, getCurrentPost } = select( editorStore ); + const { getEditedEntityRecord, canUser } = select( coreStore ); + const siteSettings = canUser( 'read', { + kind: 'root', + name: 'site', + } ) + ? getEditedEntityRecord( 'root', 'site' ) + : undefined; + const _id = getCurrentPostId(); return { slug: select( editorStore ).getEditedPostSlug(), + isFrontPage: siteSettings?.page_on_front === _id, postLink: getCurrentPost()?.link, }; }, [] ); @@ -80,7 +90,9 @@ function PostURLToggle( { isOpen, onClick } ) { aria-label={ sprintf( __( 'Change link: %s' ), decodedSlug ) } onClick={ onClick } > - { postLink } + + { isFrontPage ? postLink : `/${ decodedSlug }` } + ); }