Skip to content

Instantly share code, notes, and snippets.

@FutureMedia
Forked from lcdsantos/wp-get_id_by_slug
Last active May 6, 2017 10:41
Show Gist options
  • Save FutureMedia/892d78af67a4e7342344c9178b977bdf to your computer and use it in GitHub Desktop.
Save FutureMedia/892d78af67a4e7342344c9178b977bdf to your computer and use it in GitHub Desktop.
WordPress: Get page ID from slug WPML: Hard-coding Link
<?php
// Usage:
// get_id_by_slug('page-slug');
function get_id_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
} else {
return null;
}
}
// WPML: hard-coding the link of a page
// get_permalink( get_id_by_slug( 'page-slug' ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment