how to get page id of a page using page slug

I’m pretty new to WordPress and I was wondering if I could get a page id with its slug. Is it possible please let me know?

7

Use get_page_by_path($page_path):

$page = get_page_by_path( 'about' );
echo get_the_title( $page );

This will return a regular post object.
Documentation:
https://developer.wordpress.org/reference/functions/get_page_by_path/
https://developer.wordpress.org/reference/functions/get_the_title/

Leave a Comment