Use $_SERVER['REQUEST_URI']
instead of get_permalink()
to grab the current URL. get_permalink
will give you the full address of the current post, not the address of the URL visited.
e.g. for example.com/test/page echo $_SERVER['REQUEST_URI'];
prints /test/page
Note that this doesn’t include the hashtag, as that part never gets sent to the server, and it also doesn’t include ?foo=bar
type parameters, those are in the $_GET
array.
Related Posts:
- WordPress slug issue with non-latin characters
- Change author permalink
- How can I make Capital letter ( upper-case ) permalinks?
- Date based URLs for custom posts and pagination
- Archive permalinks
- Removing hierarchical pages in the permalink
- How to custom change author base without $this->front?
- Change permalinks structure for specific category
- Is It A Good Idea To Change Author Slug (user_nicename field) Directly In MySQL DB?
- Why can’t I save permalink “360” for a page?
- Custom post type by ID in root folder
- Permalinks Question: Adding a prefix ONLY in front of the posts
- Permalink redirection from ‘Day and name’ to ‘Post name’
- Move WordPress site from one domain to another
- Create slugs programmatically
- Make attachment pages require a base url
- How to Remove -14 from WordPress URL (Permalink)
- Rewrite URL Parameter And Force ‘Pretty’ Permalink
- How to map a URL to a specific template?
- How to hook into permalink when publishing-saving post?
- Problem duplicated shortlinks bitly
- Incorrect 404 for pages when using permalink, a static front page, and posts page
- Changing permalink changes stylesheet path?
- Multisite Network: How to change permalink structure programmatically on new blogs
- Custom Permalinks don’t work on local LAMP installation
- Problems redirecting to “pretty” permalinks (wordpress in Subdirectory)
- Remove permalink settings in post for users
- Remove multisite “blog” slug from specific custom post type
- If I change permalink structures, can I use htaccess to permanantly redirect links?
- Redirect parent taxonomy to it’s child
- WordPress Permalinks still not working despite all necessary settings
- RewriteRule accepts numbers but not letters in tag
- Avoid WordPress categorizing a permalink request as Not found 404 Page
- Pages not using permalink
- Redirects after permalink change
- WordPress permalink setup in Hindi
- Use custom post meta in permalink
- SEO: shortening permalinks to five words
- Remove -2 from URL; no duplicate pages, no images, no pages in trash
- Process all virtual sub pages on parent page
- Correct permalinks and 404-error
- Add sku to product url woocommerce [closed]
- Custom permalink with two parameters
- Press-This stopped redirecting to permalink after post publish
- Giving a new page an existing URL
- encoded search terms with %20
- Permalinks not working on new site
- Custom links in menus not working in multiple environments
- 404 permalink errors on Pages only
- What happens to the permalink that use %postname% if I change the post name
- using wp_redirect to redirect to a permalink
- old permalinks not found
- WordPress permalink from the database?
- Assigning proper permalink to blog that is part of a website
- What would cause a 500 Server Error with permalinks turned OFF?
- Changing permalinks back to default ( ?p=123 )
- permalinks on title tag
- Display parent page URL for child page
- How to set add_query_arg properly for home page?
- How to redirect old permalinks from https://exmaple.com/category/post_id to https://exmaple.com/category/post_id.html
- Double Slash After Media Path (uploads//)
- New posts link to old posts (random)
- Undefined variable: testimonial in D:\Projects\PWP-WP\wp-content\themes\blankslate-child\template-parts\fields\flex\bottom-page-block.php on line 123
- Is it possible to set public to false for the native WordPress blog
- Code snippet to add filter pre_post_link to change Media URL (post_type attachment permalink/slug)
- Custom Permalink (with category) for Pages
- WP adding noopener and noreferrer to all links
- 301 redirects after changing permalinks
- Post links broken after migration
- Rename Custom Post Slug using taxonomy
- Link works although page was moved to another location
- Permalink of post redirect to uncategorized category
- Getting current page URL when default permalink is set
- WordPress All pages but home simply read “hello”
- Make Permalinks have a custom format?
- Difference and usage of uri (e.g. get_directory_uri) and absolute path (e.g. get_directory)
- permalinks of subcategory and posts
- Fresh wordpress installation in sub-directory not accessible
- Get link from wpe_excerpt “read more” and move it
- WordPress 4.0 beta – how to change the link URL in RSS feeds
- Folder Name and Category Name WordPress
- Installing WordPress in another Install?
- using post meta data as permalink tags [duplicate]
- How to display post permalinks instead of pages?
- Incorporate single WordPress page into an existing static website [duplicate]
- How to configure WordPress to be a subdirectory of my main site as mymainsite.com/blog?
- Search points to /search/?s=KEYWORD instead of /search/KEYWORD
- How to change pagination base from slash to query form?
- WP Custom Permalink Filter
- standard post with extra parameter brings permalink problem
- Removing parent page in URL for one page
- Remove index.php from URL
- Siteurl code for links
- WordPress Permalinks 404 Not Found
- WordPress 6.1.1 UTF8 Slug Limit Increase
- 301 Redirect posts to newly added categories
- How to have category/subcategory/posttitle/ permalinks?
- make a new structure tag that does some processing
- Website appears with wrong permalink in Google’s search
- Permalink settings are stuck on https, will not update to http