FutureMedia
5/6/2017 - 10:09 AM

WordPress: Get page ID from slug WPML: Hard-coding Link

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' ));