Mika MAtikainen

Apr 15, 2020 · 4 min read

How do I get the page slug in WordPress using the get_post_field function in WordPress?


 <?php
// Get the current post or page's slug
$slug = get_post_field( 'post_name', get_post() );
echo $slug;

// Get slug for a post or page by ID
$post_id = 1;
echo get_post_field( 'post_name', $post_id );

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This