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
- How to Stop WordPress Change Slug Automatically Same as Title When Publish?
- Get default permalink structure from pretty URL’s
- Getting the Site URL Including the Front Base
- How to use relative links on my pages?
- Stop WordPress from reserving slugs for media items?
- Change slug on post creation
- WordPress Permalink changes to question mark (?) in URL
- Post type child of another post type
- Update URL Snippet to Canonical Permalink URL
- When creating a WordPress page, a “-2” suffix is added to new pages’ permalinks
- “.#[random-char-string]” being inserted at end of URLs
- How to i18n slugs for templates?
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- WordPress on a subdirectory of Laravel – WordPress pretty permalinks inner page shows laravel
- Pretty Permalinks
- Remove parent slug for child pages
- How to get url of a post from admin panel
- Replace WordPress %postname% suffix with %postid%?
- How to get the post id from a permalink?
- Change website URL without breaking links or images? WP 3.3
- How to edit the slug/permalink in Gutenberg?
- Using ‘Primary Category’ in URL
- display URL or permalink instead of page title in dashboard
- custom permalink/shortlink with base62 encoded post ID
- How can I get the permalink of a post before it is published?
- Change permalink rule if category is called “uncategorized”
- Add a URL prefix to permalinks of News category and sub-categories of posts only
- echo post-permalink without http and www
- Filter string like a slug
- Confusion about how a URL is being parsed
- CSS not loaded when omitting www. part of URL
- How can I add a page’s ID to its permalink using WP_Rewrite?
- Custom permalink for search and pagination
- Get page by path – honoring permalink settings (urls w/slashes)
- Does rename of page slugs create 301 redirects from old slug to new (same as for posts)?
- Change blog segment of URL
- How to stop WordPress from removing & from URL?
- Force wordpress to display page with same url structure as categories
- Share same Slug for a Custom Post Type and 2 Taxonomies
- How to bulk edit image url in featured image and product description?
- How to include sub directory in sitemap? [closed]
- get_permalink returning site home url instead of the url of slug being passed
- Edit page slug after save, cause 404 by linked pages
- Host frontpage via example.com and everything else via example.com/blog
- WordPress can generate numeric permalinks, which then 404
- Permalinks settings
- mod-rewrite exception? keep #hash in matching urls?
- Edit permalink for certain pages
- How to Custom Edit Post Title & Permalink Slug?
- Problem with parent page slug only in WordPress admin
- Two URLs of one post is available
- “-2” Being added to end of URL (no duplicate pages, no pages in trash)
- Change permalinks for specific pages
- Post with no tag permalink problem
- Gutenberg Editor: dynamically edit slug field based on ACF field
- Allow two posts (from different categories) to have the same slug
- How to remove category name for only one category?
- How to prevent wordpress from lowering Capitalized letters
- Customize URL for specific tags archive
- Rewrite rule not working, but only when parameter is text
- Why does one of my pages not have the option to edit the link?
- How do I use the same Tag slug for different Tags?
- Giving specific category posts its own permalink structure returns 404
- Adding query string to multiple page urls in a WordPress function
- I have Akamai pointing to a WordPress installation with a different URL. Is there a way to make WordPress use this for link generation?
- How to allow different authors to use same post slug?
- Problem with permalinks
- Allowing slash in slug/permalinks
- How to change the URL using rewrite rule in wordpress
- Get value from URL with different types of parameters
- a way to support totally different url structure
- Author permalink
- Automatically remove repeated words in slug
- When using number in url it is redircting to same page but when using character it redirects to 404
- Keep wordpress from modifying my permalinks
- Is there a way to remove the option to modify the Slug in post.php
- Issues with WordPress permalinks
- Why is there a # and other characters in URL for WordPress site?
- Custom Permalink Base
- Update permalinks after domain change
- How to avoid duplicate Url for the home page
- Change permalink in wp-property
- Display a custom slug in URL depending on user variable
- Remove parent product category slug from product_cat url woocommerce
- How to change the category and post prefix/slug to be the same in WordPress?
- Duplicate Content Issue with WordPress Permalink Structure and Primary Categories