Find us on Facebook

LightBlog
Responsive Ads Here

Thứ Sáu, 23 tháng 2, 2018

How to retrieve the slug of current page?

Question:

I am trying to retrieve the slug of the current wordpress page outside the loop. The title of the page returns with wp_title () but how can I get the slug?
<li><a href="/slug-of-current-page/"><?php wp_title("",true); ?></a></li>
Answer:

use global variable $post.
<?php 
    global $post;
    $post_slug=$post->post_name;
?>

Không có nhận xét nào:

Đăng nhận xét