1

I am building my own WordPress theme. I have the front page working. However, when I try to view a test post full of Lorem Ipsum, I get the "No matching template found" error.

I have the following code in single.php

<?php
    get_header();

    if( have_posts()){
        while( have_posts() ){
            the_post();
            the_content();
        }
    }

    get_footer();
?>

single.php is under directly my custom theme's root folder.

From what I understand, the page should just display the content, albeit without much styling. I navigated to the post using the "view post" link on the post edit page if that matters.

Just to be sure, I also placed the same code in page.php, index.php, and page.php

No success. No matter what I try, I still get "No matching template found" when navigating to the test post.

What am I missing here? Is there a way to troubleshoot the template hierarchy?

Thanks in advance.

4
  • do you have an index.php file? Themes must have an index.php file to be valid, and that file acts as the final fallback at the end of the template hierarchy. What you're describing does not make sense in a valid theme. The absolute minimum required theme needs a style.css and an index.php, even if you do not intend to use those files they must be present. Likewise single.php must be at the top level of the theme it cannot be inside a subfolder
    – Tom J Nowell
    Jan 9, 2022 at 3:32
  • 1
    Additionally, the error message you mentioned only occurs when loading a block theme template part, there is more going on here than just files in a theme, did you try to use the site editor or declare that your theme is a block based theme?
    – Tom J Nowell
    Jan 9, 2022 at 3:34
  • I have an index.php file. The code mentioned above is present in it and I still get the error. Also, how do you declare a block based theme? I am not deliberately trying do build one.
    – N.MORR
    Jan 9, 2022 at 4:06
  • do you have a theme.json? Or have set up a template for that post using the UI? It's possible to override the template of a single page and create a block based template
    – Tom J Nowell
    Jan 9, 2022 at 17:41

3 Answers 3

0

I'm still not quite too sure what happened here, but I reset WordPress without changing the theme and that resolved the issue. If I figure out what setting it was that caused it, I will post it here.

0

In my case, a WP core upgrade did not cleanly auto-install. To fix this part of the problem, I had to manually recreate the "themes" folder/directory, then reinstall my theme.

0

When dealing with the error message "No matching template found", be sure to check if the global WP_CONTENT_DIR is set correctly in your wp-config.php file.

I encountered this problem muliple times now. So I felt the urge to share this solution here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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