Skip to content

Instantly share code, notes, and snippets.

@sirtimid
Last active November 16, 2016 22:49
Show Gist options
  • Save sirtimid/f078ece786be3eefed8e135c0b9667b7 to your computer and use it in GitHub Desktop.
Save sirtimid/f078ece786be3eefed8e135c0b9667b7 to your computer and use it in GitHub Desktop.
Get a wordpress page URL by template name
<?php
if(!function_exists('get_url_by_template')){
function get_url_by_template($tmpl){
$pages = query_posts(array(
'post_type' =>'page',
'meta_key' =>'_wp_page_template',
'meta_value'=> $tmpl
));
$url = null;
if(isset($pages[0])) {
$url = get_page_link($pages[0]->ID);
}
wp_reset_query();
return $url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment