diff --git a/packages/data-stores/src/help-center/types.ts b/packages/data-stores/src/help-center/types.ts index b9f61bd923c30..f17d48063305e 100644 --- a/packages/data-stores/src/help-center/types.ts +++ b/packages/data-stores/src/help-center/types.ts @@ -24,6 +24,7 @@ export interface HelpCenterSite { ID: number | string; name: string; URL: string; + domain: string; plan: Plan; is_wpcom_atomic: boolean; jetpack: boolean; diff --git a/packages/help-center/src/hooks/use-content-filter.ts b/packages/help-center/src/hooks/use-content-filter.ts index b836032ef7af4..df97d5b76dbee 100644 --- a/packages/help-center/src/hooks/use-content-filter.ts +++ b/packages/help-center/src/hooks/use-content-filter.ts @@ -1,5 +1,6 @@ import { useEffect, useMemo } from '@wordpress/element'; import { useNavigate, useSearchParams } from 'react-router-dom'; +import { useHelpCenterContext } from '../contexts/HelpCenterContext'; const isThisASupportArticleLink = ( href: string ) => /wordpress\.com(\/\w\w)?(?=\/support\/)|support\.wordpress\.com/.test( href ); @@ -8,6 +9,7 @@ export const useContentFilter = ( node: HTMLDivElement | null ) => { const navigate = useNavigate(); const [ searchParams ] = useSearchParams(); const link = searchParams.get( 'link' ) || ''; + const { site } = useHelpCenterContext(); const filters = useMemo( () => [ @@ -42,6 +44,18 @@ export const useContentFilter = ( node: HTMLDivElement | null ) => { }, }, + { + pattern: 'a[href*="wordpress.com/plans/"], a[href^="/"]', + action: ( element: HTMLAnchorElement ) => { + const href = element.getAttribute( 'href' ) as string; + const currentSiteDomain = site?.domain; + + if ( currentSiteDomain ) { + element.setAttribute( 'href', new URL( `${ href + currentSiteDomain }` ).href ); + } + }, + }, + /** * Fix table of content jump-to links. */