WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)

I’ve encountered a strange error while developing a custom theme.

After finishing editing the template for a custom post type single view, I passed onto working at the template files for pages and I ealized that WordPress was actually pointing to index.php template file rather than page.php in my theme for generating the page appearance.

I tried to change settings for website home and blog home in “reading” settings. I tried to refresh permalinks structure (normally I’m using %postname%). I also tried reverting to standard /?=post_id structure. In that case works fine… but anything with %postname% won’t work.

I disabled plugins, but nothing changes. It simply refuses to work with pretty permalinks.
Actually permalinks work fine for my custom post type and it won’t throw 404 errors. But for every single page and post will try to fetch index.php rather than single.php and page.php (or subsequent templates for pages). I checked the configuration for my custom post type… but there’s no possible conflict with pages (the url rewrite is totally different than any standard wordpress string).

I checked my .htaccess which is pretty standard as in most of my installations:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

UPDATE

I decided to throw everything away, being a test development site and started over on a clean install. Dumped the whole DB, trashed the installation files. Clean install and enabled wp_debug=true. At the beginning I noticed an error from the Dashboard:

ERROR: The themes directory is either empty or doesn’t exist. Please check your installation.

I think this is because I renamed the wp-content folder to “content”

I’ve done this before on other installations with this code (of course “mydomain” is my actual domain in my wpconfig…)

define('WP_CONTENT_FOLDERNAME', 'content' );
define('WP_CONTENT_DIR', ABSPATH . WP_CONTENT_FOLDERNAME );
define('WP_CONTENT_URL', 'http://mydomain.com/' . WP_CONTENT_FOLDERNAME );
define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' );

After double checking and reloading the page somehow the error string disappeared. I was able to install the theme correctly (therefore WordPress must have been aware of its location folder…)

However, the URL permalinks problem persists (wants to fetch index.php instead of page.php template for pages or single.php for posts ). This is driving me insane since it’s a clean new installation.

UPDATE 2

now I’m testing with TwentyEleven/Ten and it’s still throwing the same error… so I must exclude plugins and my custom theme… this has probably to do with my server config, htaccess or wpconfig probably… but I really wonder… because this is running on the same server where I have half dozen of wordpress sites configured in a similar way

UPDATE 3

after changing and updating the wp-config.php file several times I got it working at times… but for some reason it keeps breaking again… single blog posts and pages get redirected to index.php (blog home) or page template holding the blog home (if set in “reading” settings from wordpress admin). Custom post types, archives and bbpress forum pages (individual posts and archives), taxonomies… they all work fine. It’s just pages and posts. I double checked the php configuration and server variables, it all appears normal

5 Answers
5

I’m going to answer my own question for the sake of people who might run in the same issue as me

in my setup I had a plugin handling taxonomies; one of these had the rewrite slug set to “year” – well, it turns out this conflicts probably with date based archives (?) and caused my posts and pages not loading but rather redirecting the user to the blog home – evidently there was some issue in WordPress templating hierarchy; I haven’t investigated further

I didn’t catch the error quickly because I didn’t flush permalinks properly while deactivating plugins – also for some reason the error appeared randomly (sometimes my permalinks DID work despite the taxonomy rewrite was still set)

I ended up by renaming the slug into “period”, then deleting the .htaccess, recreating it, and creating/flushing permalinks from WordPress permalinks page

that seems to have fixed it once and for all

so… if you happen to be in a similar situation, check check check everything that is altering the permalink structure in some manner, even custom post types and taxonomies, think about the slug you’re using and if it may conflict with something else even not obvious

cheers

Leave a Comment