最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

hooks - Set custom directory in theme for page templates

programmeradmin2浏览0评论

I have a directory structure in my theme like this:

src/
  templates/
    pages/
      - faqs.php
    views/
      - page.php

In my custom functions I have a hook that tells WordPress to look in the src/templates/views directory for basic templates like page.php, etc. This works fine.

What I would like to do is tell WordPress to look in src/templates/pages for any custom page templates. From what I understand, WordPress scans the theme directory structure for any page templates but it only goes one-level deep.

For example, my faqs.php file has a template name of FAQs:

<?php
/*
  Template Name: FAQs
*/
?>

If I move faqs.php to the src directory it appears in the WP Admin as an available option in the Template dropdown. But when I move it back to src/templates/pages it is no longer registered.

I have looked for a variety of solutions but haven't found exactly what I'm looking for. It seemed like the theme_page_templates hook might be the answer, but I don't want to have to create the names of the template files in the select list, etc. I would prefer to just tell WordPress where to look and then let WP handle the rest from there. Not sure if that is possible though.

发布评论

评论列表(0)

  1. 暂无评论