Skip to content

Instantly share code, notes, and snippets.

@someguy9
Created October 31, 2022 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save someguy9/a7affe48d9fc40ac406acb0389eb3c19 to your computer and use it in GitHub Desktop.
Save someguy9/a7affe48d9fc40ac406acb0389eb3c19 to your computer and use it in GitHub Desktop.
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment