Skip to content

Instantly share code, notes, and snippets.

@jayllellis
Last active February 4, 2019 16:34
Show Gist options
  • Save jayllellis/2e6f4257a07b7ce9f6bcb307dd8c31a3 to your computer and use it in GitHub Desktop.
Save jayllellis/2e6f4257a07b7ce9f6bcb307dd8c31a3 to your computer and use it in GitHub Desktop.
Get page IDs for certain kinds of pages
<?php
// Special pages -----------------
$frontpage_id = get_option( 'page_on_front' );
$blog_id = get_option( 'page_for_posts' );
// Page templates -----------------
$about_templates = get_pages(array(
'meta_key' => '_wp_page_template',
'meta_value' => 'page-about.php'
));
if($about_templates){
$about_id = $about_templates[0]->ID;
$about_url = get_permalink($about_id);
}
else{
$about_url = '#';
}
// OR:
$args = [
'post_type' => 'page',
'fields' => 'ids',
'nopaging' => true,
'meta_key' => '_wp_page_template',
'meta_value' => 'page-about.php'
];
$about_templates = get_posts( $args );
if($about_templates){
$about_id = $about_templates[0]->ID;
$about_url = get_permalink($about_id);
}
else{
$about_url = '#';
}
// Privacy Policy Page -----------------
get_privacy_policy_url(); // Retrieves the URL to the privacy policy page.
the_privacy_policy_link(); // Displays the privacy policy link with formatting, when applicable.
get_the_privacy_policy_link(); // Returns the privacy policy link with formatting, when applicable.
?>
<!-- Usage: -->
<a href="<?php echo $about_url; ?>">About Us</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment