Learndash自定义分类模板命名问题求助
Hey there! Let's troubleshoot why your taxonomy-course-category.php template isn't kicking in for your LearnDash course category page (http://example.com/course-category/photoshop/). The most common culprit here is a mismatch between the taxonomy slug you're targeting and what LearnDash actually uses under the hood.
Step 1: Verify the Actual LearnDash Course Category Taxonomy Slug
LearnDash doesn't use course-category as the official taxonomy slug for its course categories—instead, it defaults to ld_course_category. To confirm this:
- Add a quick debug snippet to your theme's
functions.phpfile (or temporarily add it to a generic template likearchive.php):<?php if (is_tax()) { $tax_obj = get_queried_object(); var_dump($tax_obj->taxonomy); // This will print the actual taxonomy slug } ?> - Visit your course category page, and you'll see the taxonomy slug is
ld_course_category, notcourse-category.
Step 2: Rename Your Template File Correctly
Once you confirm the taxonomy slug, rename your template to match:
- For all course category pages: Use
taxonomy-ld_course_category.php - For the specific "photoshop" category only: Use
taxonomy-ld_course_category-photoshop.php
Step 3: Rule Out Other Potential Issues
If the template still isn't working after renaming, check these:
- File Location: Ensure the template is placed directly in your active theme (or child theme) root directory—not in a subfolder like
/templates/unless your theme explicitly supports that structure. - Cache: Clear your WordPress cache, browser cache, and any server-level cache (like Cloudflare or WP Rocket) to make sure the new template is loaded instead of cached old files.
- Template Hierarchy Priority: Confirm your theme doesn't have a higher-priority template (like
archive.php) that's overriding your taxonomy template. WordPress prioritizestaxonomy-{taxonomy}.phpover generic archive templates, so this is less likely, but worth double-checking.
Once you fix the template filename to match LearnDash's actual taxonomy slug, your custom template should load as expected!
内容的提问来源于stack exchange,提问作者Ehsan Musavi

