Skip to main content
231 votes
Accepted

How to get URL of current page displayed?

get_permalink() is only really useful for single pages and posts, and only works inside the loop. The simplest way I've seen is this: global $wp; echo home_url( $wp->request ) $wp->request ...
Jacob Peattie's user avatar
64 votes

Change media item permalink

Go to Media Library Find the Image Click Edit Image Click Edit more details (at bottom right, very easy to miss) Find the Screen Options (top right) and enable the Slug checkbox Scroll down to ...
Devin Peterson's user avatar
49 votes
Accepted

Get the blog page URL set in Options

As of WordPress 4.5 you can use: get_post_type_archive_link( 'post' ); This handles the logic of getting the correct URL regardless of whether posts show up on the homepage or in a specified page.
SeventhSteel's user avatar
  • 1,707
44 votes

Custom Post Type pages are "not found"

You don't have to edit your php code! While you can do this in the function that registers your custom post type, like the other answers, you can also do this in the settings menu, thus avoiding ...
Danny's user avatar
  • 561
31 votes

Changing permalinks gives me 404 errors on nginx

I'm using wordpress multisite with custom permalink setting: /%category%/%postname%/ /etc/nginx/site-available/domain.conf On server{ location / { try_files $uri $uri/ /index.php?q=$uri$args; } ...
Domi's user avatar
  • 411
31 votes

How to get URL of current page displayed?

You may use the below code to get the whole current URL in WordPress: global $wp; $current_url = home_url(add_query_arg(array(), $wp->request)); This will show the full path, including query ...
rescue1155's user avatar
28 votes
Accepted

Stop Wordpress appending `-2` to the end of my url after i change it

I know this topic is old, but I was having the same issue, and none of the suggested fixes worked. I didn't have any pages still in trash. I didn't have a category with the same name as my page. I ...
Ed Selby's user avatar
  • 396
28 votes
Accepted

How does WordPress create URLs that Apache knows about?

Actually there is no communication happening between Apache and WordPress. The "magic" is happening in Apache mod_rewrite rules. For a standard WordPress installation, you have the following rules in ...
Fayaz's user avatar
  • 8,967
24 votes

Get page permalink without wpurl

There's actually a core function for this now. wp_make_link_relative($url) Convert full URL paths to relative paths. Removes the http or https protocols and the domain. Keeps the path '/' at the ...
Levi Cole's user avatar
  • 613
22 votes
Accepted

Can I use REST-API on plain permalink format?

Yes you can. Just add the rest_route query parameter. So https://wordpress.org/wp-json/ would become https://wordpress.org/?rest_route=/ Or https://wordpress.org/wp-json/wp/v2/ would become https://...
kraftner's user avatar
  • 5,618
21 votes

How to get URL of current page displayed?

Why not just use? get_permalink( get_the_ID() ); That is for single pages. For category pages, use this: get_category_link( get_query_var( 'cat' ) ); Simple script to get the current URL of any page:...
Dario Zadro's user avatar
19 votes

Remove the blog slug from Wordpress Multisite root node

Step 1: Go to /wp-admin/network/site-info.php?id=1 Network Admin -> Sites -> Edit -> check Permalink Structure. Edit as per your requirement. Step 2: Go to normal site level Settings -> ...
Saran's user avatar
  • 361
19 votes

How to get URL of current page displayed?

In my case, this code worked fine: $current_url = home_url($_SERVER['REQUEST_URI']) I hope it will help someone, I tried all answers but this one was helpful.
Akmal's user avatar
  • 291
18 votes
Accepted

What is the difference between get_permalink vs get_the_permalink?

Nothing. get_permalink() is the original function, and is used to get the permalink URL for a post. get_the_permalink() was introduced in 3.9 simply so the permalink function was consistent with the ...
Jacob Peattie's user avatar
15 votes

How can I get the privacy policy page?

WordPress stores the page id for the privacy policy page in the options table. To get the value, you can use: $privacy_policy_page = get_option( 'wp_page_for_privacy_policy' ); if( $...
Johansson's user avatar
  • 15.3k
14 votes

How can I get the privacy policy page?

These functions are available since 4.9.6 for the privacy policy url and link: get_privacy_policy_url() - filterable with the privacy_policy_url filter. get_the_privacy_policy_link() - filterable ...
birgire's user avatar
  • 67.6k
13 votes
Accepted

Change media item permalink

Yes! Go to your Media Library Click the Image Click the "Edit more details" link If you cannot see a way to edit the permalink, click the "Screen Options" button at the top of the ...
ngearing's user avatar
  • 2,164
13 votes
Accepted

Get current URL (permalink) without /page/{pagenum}/

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 ...
GKS's user avatar
  • 1,306
13 votes

Get current URL (permalink) without /page/{pagenum}/

Actually the easiest would be to use get_pagenum_link() which will return you the current URL without any /page/* paramaters. Bonus You can also simply use it to build "Previous" and "Next" links ...
leymannx's user avatar
  • 3,201
13 votes
Accepted

Search custom taxonomy term by name

// We get a list taxonomies on the search box function get_tax_by_search($search_text){ $args = array( 'taxonomy' => array( 'my_tax' ), // taxonomy name 'orderby' => 'id', ...
TrubinE's user avatar
  • 1,037
13 votes
Accepted

Page begins with number, WordPress adds 2

Within the wp_unique_post_slug function, checks are made to "Prevent new post slugs that could result in URLs that conflict with date archives." Here's the relevant code from line 3812 from wp-...
Andrew's user avatar
  • 919
12 votes

Resolve a custom post type name vs. page permalink conflict (same slug)

I'm not high enough reputation to comment on @Carl's post, but his is the correct answer (at least to this situation of keeping the page slug and custom post type slug the same and not using an ...
Andrew Herder's user avatar
12 votes

Changing permalinks gives me 404 errors on nginx

Had to add this piece of code to both the /sites-available/your-settings-file and /sites-enabled/your-settings-file: server { [...] if (!-e $request_filename) { rewrite ^.*$ /index.php last; } [...
Angelo Reale's user avatar
12 votes

Disable Attachment Pages Completely

You can filter default rewrite rules and remove those for attachments: function cleanup_default_rewrite_rules( $rules ) { foreach ( $rules as $regex => $query ) { if ( strpos( $regex, '...
Ihor Vorotnov's user avatar
12 votes

How to get URL of current page displayed?

The following code will give the current URL: global $wp; echo home_url($wp->request) You can use the below code to get the full URL along with query parameters. global $wp; $current_url = ...
Adiyya Tadikamalla's user avatar
12 votes

'publicly_queryable' => false not working as expected for custom post_type

If you want archives, but not singular view, then 'publicly_queryable' can't help you. If you want that visiting a singular post send a 404... just do it. You can hook 'template_redirect' and ...
gmazzap's user avatar
  • 46.2k
11 votes
Accepted

How to filter to output of the get_permalink() function

Note that post_link filter is only for the post post type. For other post types these filters are available: post_type_link for custom post types page_link for page attachment_link for attachment ...
birgire's user avatar
  • 67.6k
10 votes

Change media item permalink

In Media Library, I noticed that when media file is not Attached to a page the permalink is not editable. When they are attached, permalink editing is permitted.
Andy's user avatar
  • 101
10 votes

Get current URL (permalink) without /page/{pagenum}/

Answer by Govind Kumar worked, however, it only returned the URL if /page/{pagenum}/ was present in the URL and returned nothing if not. I needed a universal solution that will always return the base ...
Ihor Vorotnov's user avatar
9 votes

Permalinks Question: Adding a prefix ONLY in front of the posts

1) Add this rewrite at the end of you function.php function add_rewrite_rules( $wp_rewrite ) { $new_rules = array( 'YOUR_PREFIX/(.+?)/?$' => 'index.php?post_type=post&name='. $...
Fury's user avatar
  • 191

Only top scored, non community-wiki answers of a minimum length are eligible