I have the following custom page template filenames:

  • template-about-1.php
  • template-about-2.php
  • template-home-1.php
  • template-home-2.php

I have this function to get_page_templates:

function get_page_templates_select() {
 $teh_cats = get_page_templates();
 foreach ( $teh_cats as $template_name => $template_filename ) {
     $results[] = $template_name;
   return $results;

How can I modify the function to ONLY return the templates that have "home" in their filename?


Figured it out after thinking it through..

if (stripos(strtolower($template_filename), 'home') !== false) {
    $results[] = $template_name;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.