Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Graham Kite
PLUS
Graham Kite
Courses Plus Student 8,123 Points

Wordpress theme error

I have a wordpress theme that shows a "404 in not found in the title" and the home page shows as blank. IE no content.

This is the code in the header.php

<title><?php if (is_home()) { echo bloginfo('name'); } elseif (is_404()) { echo '404 Not Found'; } elseif (is_category()) { echo 'Category:'; wp_title(''); } elseif (is_search()) { echo 'Search Results'; } elseif ( is_day() || is_month() || is_year() ) { echo 'Archives:'; wp_title(''); } else { echo wp_title('|',true,'right') . bloginfo('name'); } ?> </title>

The ' are single quotes so they should work. The code says if is home and the page is home, so I would not expect an error there.

I get a page title on every page except the home page. And also no content. What am I missing here, and if not here where should I be looking and what for?

Graham Kite
Graham Kite
Courses Plus Student 8,123 Points

I have changed the header code for one I know was working. So there must be a bug somewhere in the theme.

I am seeing a sidebar optin that is generated by a custom post type.. Not sure if that could be causing the issue.

How/where do I go about trying to debug and fix?

3 Answers

Kevin Korte
Kevin Korte
28,149 Points

Are you confusing home and front-page? Do have a front-page set?

John Locke
John Locke
15,479 Points

Graham:

Does your theme have a home.php or index.php file? The home.php will be the default home page if there is no specific page set to Home. If there is no home.php, your theme will look for the index.php. Make sure to set either your latest posts or a specific page to Home in your General Settings.

Graham Kite
PLUS
Graham Kite
Courses Plus Student 8,123 Points

@Kevin. no confusion. Whatever page is set as the front-page or (home page has the error). I can change the static page and the new one shows the error.

@John Has an index.php but no home.php. I tried creating a new template last night and that did not work. I will try using a home.php today

pages and posts set correctly as are permalinks and I tested in another theme and it worked. So unless I want to do a lot of duplicated work and cpt and fields I am stuck fixing this theme, which I would prefer.

Graham Kite
Graham Kite
Courses Plus Student 8,123 Points

have tested a homepage with just a <p> tag and a line of text. The 404 error goes, none of the pages display titles and the static/home/front-page still display the header, menu and optin, instead of just a single line of text.

So there is a issue in the code somewhere. Problem for me is I have no idea where to go from here.

Graham Kite
Graham Kite
Courses Plus Student 8,123 Points

By a process of replacing code from templates and php files, I have worked out there is a single-optinpage.php template that is several layers deep in the structure and that file is being called in several templates.

I can set the home page to page.php, home,page.php, use different templates, remove all the code from the php files and it still pulls content coming form the single-optinpage.php.

What should I do next?