Skip to content

Instantly share code, notes, and snippets.

@pbowyer
Last active February 23, 2018 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbowyer/4e32af55ce4fb0e81ea8c29ba41119e7 to your computer and use it in GitHub Desktop.
Save pbowyer/4e32af55ce4fb0e81ea8c29ba41119e7 to your computer and use it in GitHub Desktop.
Need to find which pages on a WordPress site are using a template? Upload this, create a page, select this template and 'Preview'. Delete after use.
<?php
/*
* Template Name: [ADMIN] List templates
*/
?>
<h2>Usage</h2>
<p>Append <code>?template=template-name.php</code> to this page URL</p>
<h2>Pages using <code><?php echo $_REQUEST['template'] ?></code></h2>
<?php
$pages = get_pages(array(
'meta_key' => '_wp_page_template',
'meta_value' => $_REQUEST['template'],
));
if(!empty($pages))
{
foreach($pages as $page): ?>
<p><a href="<?php echo get_permalink($page) ?>"><?php echo $page->post_title ?></a></p>
<?php
endforeach;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment