Last active
August 18, 2023 16:02
-
-
Save lepittenger/a1dbb28e14e453a14369e921d0d5c05d to your computer and use it in GitHub Desktop.
Get link by page template name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Retrieve the URL of the page using a template. | |
* | |
* @author Lauren Levin (Pittenger) | |
* | |
* @param string $template_name The name of the page template, ex. 'page-templates/countries.php'. | |
*/ | |
function get_link_by_page_template_name( $template_name ) { | |
$url = null; | |
$pages = get_pages( | |
array( | |
'meta_key' => '_wp_page_template', | |
'meta_value' => $template_name, | |
) | |
); | |
if ( isset( $pages[0] ) ) { | |
$url = get_page_link( $pages[0]->ID ); | |
} | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment