You can get the current URL through home_url( $wp->request )
.
Try the example below:
global $wp;
// get current url with query string.
$current_url = home_url( $wp->request );
// get the position where '/page.. ' text start.
$pos = strpos($current_url , '/page');
// remove string from the specific postion
$finalurl = substr($current_url,0,$pos);
echo $finalurl;
Related Posts:
- Custom permalink for search and pagination
- Stop WordPress appending `-2` to the end of my url after i change it
- How to use relative links on my pages?
- WordPress Permalink changes to question mark (?) in URL
- How to prevent apostrophes and quotes from appearing in permalinks?
- Date based URLs for custom posts and pagination
- Removing hierarchical pages in the permalink
- Update URL Snippet to Canonical Permalink URL
- why does anchor name add a slash to url?
- “.#[random-char-string]” being inserted at end of URLs
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- WordPress on a subdirectory of Laravel – WordPress pretty permalinks inner page shows laravel
- Pretty Permalinks
- How to create a permalink structure for posts in a specific category
- How to get url of a post from admin panel
- Limiting the number of words or characters in the slug/permalink
- How to increase the character limit for post name of 200?
- How to get the post id from a permalink?
- Change website URL without breaking links or images? WP 3.3
- WordPress 3.4 Permalinks Redirection Problem
- How to Remove -14 from WordPress URL (Permalink)
- Using ‘Primary Category’ in URL
- Add ‘articles’ prefix before blog posts url without affecting pagination
- 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
- Get canonical link
- Confusion about how a URL is being parsed
- Clean install – Changing permalinks in twentyeleven give 404
- wordpress api using rest_route for other pages
- Get page by path – honoring permalink settings (urls w/slashes)
- How to Get Page 2 / Paginated RSS Feed with Custom Permalink Structure?
- Change blog segment of URL
- Pagination Issue – /page/2 404
- How to stop WordPress from removing & from URL?
- Force wordpress to display page with same url structure as categories
- How to bulk edit image url in featured image and product description?
- How can i have a custom post type with more slugs for each post?
- URL rewriting: removing the site’s basename for a specific category
- How to include sub directory in sitemap? [closed]
- Remove -2 from URL; no duplicate pages, no images, no pages in trash
- Host frontpage via example.com and everything else via example.com/blog
- WordPress can generate numeric permalinks, which then 404
- Pre-populate Slug / Permalink with URL
- How to use all tags in post permalinks
- Permalinks settings
- mod-rewrite exception? keep #hash in matching urls?
- How to handle paging/pagination with a custom permalink?
- Edit permalink for certain pages
- Remove parent page from url
- Suddenly new posts have the default permalink instead of the post name
- Change permalink structure for pagination only
- 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)
- Pagination using paginate_links
- Change permalinks for specific pages
- Pagination url for page template
- replacing post ID by custom post name in url
- Post with no tag permalink problem
- Can I change the URL structure for a CPT only?
- How do I structure my permalinks in WordPress?
- How to redirect old permalinks from https://exmaple.com/category/post_id to https://exmaple.com/category/post_id.html
- Make a post inaccessible without a unique ID in the URL
- assets aren’t loading on a page but loads on others? slug permalink conflict?
- Whole site’s pagination not working after rewriting product permalink
- Customize URL for specific tags archive
- WordPress /page/2 gives 404 when custom permalinks is set to %category%%postname%
- Change Project permalink to custom URL
- Why does one of my pages not have the option to edit the link?
- Giving specific category posts its own permalink structure returns 404
- Extra url paths as variable
- How to create a standard WP Page that has the same url as an archive
- Adding query string to multiple page urls in a WordPress function
- Post links broken after migration
- I have Akamai pointing to a WordPress installation with a different URL. Is there a way to make WordPress use this for link generation?
- Added a prefix in URL permalink structure but the old structure still working!
- 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
- How to change URL of my pages?
- Difference and usage of uri (e.g. get_directory_uri) and absolute path (e.g. get_directory)
- When using number in url it is redircting to same page but when using character it redirects to 404
- WordPress Pagination Not Working After Transfer from Localhost
- Add Custom Pagination Permalink
- Search page Paginations not working
- Issues with WordPress permalinks
- How to display post permalinks instead of pages?
- Custom Permalink Base
- Pagination is not working, how to trace it properly?
- Update permalinks after domain change
- How to change pagination base from slash to query form?
- How to avoid duplicate Url for the home page
- Change permalink in wp-property
- Removing parent page in URL for one page
- How to get the perfect WordPress, WooCommerce, Custom Post Type pretty permalinks?
- WordPress keep redirecting me to random URLs
- Remove parent product category slug from product_cat url woocommerce