I want to get “abc_15_11_02_3” from http://example.com/project_name/abc_15_11_02_3/. How can i do this?
12 comments
Comments are closed.
I want to get “abc_15_11_02_3” from http://example.com/project_name/abc_15_11_02_3/. How can i do this?
Comments are closed.
You can get that using the following methods:
Or You can use this easy code:
If you want to get slug of the post from the loop then use:
If you want to get slug of the post outside the loop then use:
You can do this is in many ways like:
1- You can use WordPress global variable
$post
:2- Or you can get use:
3- Or get full url and then use the PHP function
parse_url
:I hope above methods will help you.
this simple code worked for me:
Best option to do this according to WP Codex is as follow.
Use the global variable $post:
WordPress: Get post/page slug
You can retrieve it from the post object like so:
use global variable $post
Here is most advanced and updated version what cover many cases:
This is collections from the best answers and few my updates.
I came across this method and I use it to make div IDs the slug name inside the loop:
Current Post object.
Other Options:
Any Post using ID.
In the loop
Outside the loop using ID