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?
Best option to do this according to WP Codex is as follow.
Use the global variable $post:
<?php
global $post;
$post_slug = $post->post_name;
?>
You can retrieve it from the post object like so:
global $post;
$post->post_name;
use global variable $post
<?php
global $post;
$post_slug=$post->post_name;
?>
If you want to get slug of the post from the loop then use:
global $post;
echo $post->post_name;
If you want to get slug of the post outside the loop then use:
$post_id = 45; //specify post id here
$post = get_post($post_id);
$slug = $post->post_name;
this simple code worked for me:
$postId = get_the_ID();
$slug = basename(get_permalink($postId));
echo $slug;
You can get that using the following methods:
<?php $post_slug = get_post_field( 'post_name', get_post() ); ?>
Or You can use this easy code:
<?php
global $post;
$post_slug = $post->post_name;
?>