Instead of hardcoding the slug, instead store the ID in an option and then use it to call get_permalink(). You can also avoid hardcoding the $baseUrl and rely on a nav menu or button block instead so that it automatically updates.
For example,
$page_id = .....; // maybe a `get_option` call or something else? Depends where you want to store the ID of the page
$baseUrl = get_permalink( $page_id );
In general, avoid storing URLs slugs or URL fragments, and don’t put “magic values” such as numebers and strings in your PHP code.
Related Posts:
- How to prevent apostrophes and quotes from appearing in permalinks?
- How to Remove Slug From Database?
- How to make draft posts or posts in review accessible via full url / slug?
- Limiting the number of words or characters in the slug/permalink
- Make attachment pages require a base url
- Non latin post slug truncate
- Pre-populate Slug / Permalink with URL
- Suddenly new posts have the default permalink instead of the post name
- Bulk append URL (add word to slug)
- Remove international characters from slug – Almost done – Bit help
- How to remove slug from front page?
- How do I structure my permalinks in WordPress?
- assets aren’t loading on a page but loads on others? slug permalink conflict?
- How to create a standard WP Page that has the same url as an archive
- Can’t Remove Unnecessary Slug
- Is it possible to get a page link from its slug?
- How does WordPress create URLs that Apache knows about?
- Stop WordPress appending `-2` to the end of my url after i change it
- Get current URL (permalink) without /page/{pagenum}/
- How to get pretty URLs with add_query_arg in permalinks
- Creating custom permalink structure for languages
- Removing the redirect after changing a page’s slug
- How does wordpress keep track of post id when post id is not used in permalinks?
- Prevent WordPress from abbreviating-long-slugs…-in-the-admin
- Adding another word in front of post url
- Why don’t WordPress post slugs allow accents?
- How can I force WordPress to redirect to canonical permalinks?
- Remove subfolders from URL
- Remove parent slug for child pages
- flexible rewrite ‘ramble’ URLs with WordPress
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- Gutenberg Editor: dynamicaly change slug field with an ACF field
- How to Modify Existing Rewrite Rules?
- Is using %postname% for permalinks really that bad for performance?
- Can two products with the same name but different category produce unique URLs?
- Change author slug and functionality
- Get closest page ID from URL
- How to modify the slug for the default wp posts without affecting other posttypes?
- Auto-create a pretty permalink for a bunch of posts
- Setting up two separate blogs while using WordPress as a CMS
- How to show the homepage on a different url, like site.com/blog instead of site.com?
- Get new WordPress slug from old wordpress slug
- filtering special chars from post slug
- Is there a link parameter that will show me all my published pages?
- force permalink slug for page vs post_type slug parent
- wp not making CPT permalink / slugs unique
- Get the url of a page template without using the page slug and ID
- WordPress keeps giving me the wrong permalink
- display dynamic content based on url slug on custom page
- How to generate a list of all urls
- Relative v.s. absolute URLs: which ones should I use for cross-domain portability?
- Custom permalinks in WordPress
- wordpress how to replace url /bar with foo/bar for custom post type
- cannot link a external url, present page url acting as parent url
- how do prevent wordpress from creating permalinks for media files
- How to create posts or pages with the names in wordpress?
- replicate url permalink after migrating to wordpress
- Can I change the URL structure for a CPT only?
- How to redirect old permalinks from https://exmaple.com/category/post_id to https://exmaple.com/category/post_id.html
- New posts link to old posts (random)
- Modify post slug before saving
- Does wordpress take care of slug collisions?
- Make a post inaccessible without a unique ID in the URL
- A different permalink structure for different categories
- Multiple Taxonomy Items for Separate URLs
- URL gives 404 error of my subfolder site when i change permalink
- Code snippet to add filter pre_post_link to change Media URL (post_type attachment permalink/slug)
- How to construct a dynamic rewrite rule for child pages that passes more than one query var
- Nested permalink without dummy parent page
- home page slug editor missing from WordPress
- Custom Taxonomy rewrite rule causes 404 error on page or single post depending on if it’s set to “True” or “False”
- Post links broken after migration
- Added a prefix in URL permalink structure but the old structure still working!
- Problem with permalinks
- rebuilding/ rewriting a url to make it SEO friendly
- add bar in paging in the URL
- WordPress Page URL
- Force/Limit the post/page slug to accept only url friendly characters
- Difference and usage of uri (e.g. get_directory_uri) and absolute path (e.g. get_directory)
- Imported posts using wrong domain name
- Uppercase vs. Lowercase page slugs
- Possible to hide parts of the slug from get_template_directory_uri and bloginfo(‘template_directory’)
- How to display post permalinks instead of pages?
- Why is there a # and other characters in URL for WordPress site?
- How to update permalink on the fly?
- How to avoid duplicate Url for the home page
- Are custom page templates being used to get this permalink structure
- Display a custom slug in URL depending on user variable
- Include language variable in url
- Removing parent page in URL for one page
- Different template fallback when changing permalinks
- Hide custom post type slug url from search engine [closed]
- Pages resolve at different URLs (different capitalizations)
- Standard Htaccess directives disappear by themselves
- WordPress not remembering old slugs for pages
- Change default URL (or permalinks) in the back-end
- Append slug of each blog post with a hash based on a custom field
- how to ensure url uses post_name and not query post id?
- Creating WordPress pages with post name as slug
- WordPress homepage shows default theme after migration – logged-out users see different content