WordPress custom theme going to 404.php - php

I created a custom theme with (for now) nothing special in it. My functions.php only contains an action hook to wp_enqueue_scripts and I have the following files:
header.php
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
index.php
<?php
get_header(); ?>
INDEX
<?php get_footer(); ?>
footer.php
<?php wp_footer(); ?>
</body>
</html>
archive.php
<?php get_header(); ?>
ARCHIVE
<?php get_footer(); ?>
404.php
<?php get_header(); ?>
404
<?php get_footer(); ?>
functions.php
<?php
# WP Basics
//include_once(get_stylesheet_directory() . "/functions/menus.php" );
include_once(get_stylesheet_directory() . "/functions/scripts.php" );
Now I have the following issue, when I go to the front page it shows the correct page, but when I got to any other page, archive, or what so ever it ends in the 404.php.
I did check the following:
Disable all plugins (no result)
Enable default theme (twenty-seventeen, everything is fine)
Permalinks are on "/%postname%/" when I set it to "plain" everything works
Check if there is a .htaccess somewhere where it doesn't belong (isn't)
Check if filenames are correct (they are)
So needless to say I'm really stuck, I have made several custom theme's and never had this issue before. Does anyone have any idea?
Kind regards,
Augus

You are missing style.css file in your theme as in your question you haven't mention style.css.
And style.css is most required file to create the theme in wordpress so please add style.css in your theme and it will work for sure.

Alright so i fixed it, thanks for all the help.
I added a rewrite rule which wasn't correct, then i deleted it again. But somehow this rewrite didn't go away and was only active for my theme.
I was under the assumption that when i saved the permalinks again the rewrite rules were flushed, but this wasn't the case. So i added the following snippet to my functions.php and it worked.
add_action( 'init', 'shoe_flush_rewrite_rules' );
function shoe_flush_rewrite_rules() {
flush_rewrite_rules();
}
Remember to delete this snippet when everything works again, cause it doesn't need to be run everytime.

Related

singular.php doesn't show the content

I'm trying to develop my first wordpress themes, but now I have a quite weird problem. My singular.php page seems to not work. whatever I put in the page doesn't show up. as if the wordpress core doesn't recognize the file. while I used the same content for another theme for the same website and it worked properly.
It doesn't even show my header and footer. and when I inspect the page it's completely empty!
I tried setting the index.php file, but the same result was there :( nothing to show.
the content of the page is:
<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php get_header();?>
</head>
<body>
<?php get_template_part('template-parts/header/header-bar');?>
<?php
if (have_posts()):
while (have_posts()) : the_post();
the_content();
endwhile;
else:
echo '<p>Sorry, no posts matched your criteria.</p>';
endif;
?>
<?php get_footer();?>
</body>
</html>
UPDATE
for some reason, this content works in page.php, I don't know why singular.php and index.php don't work. according to wordpress Template Hierarchy they should show the content in case of existence.

Why won't my html render in my header.php file?

I have a barebone header.php file that looks like this so far
<!doctype html>
<html>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<header class="testB">
<p>header section</p>
</header>
The header loads into the index.php file perfectly fine, however it doesn't render my <header> tag with the text. I just checked out a couple videos and tutorials to see if there's something else I need to do and they all seem to dive right into customizing everything and have it render. The only thing present is the title of my website which wordpress injects on its own. Any clue as to why this won't just work like it seems to in the tutorials?
Here's my index.php and footer.php just so you guys can see the overall setup.
index.php
<?php get_header(); ?>
<p class="test">body</p>
<?php get_footer(); ?>
footer.php
<footer>
<p>footer</p>
<?php wp_footer(); ?>
</footer>
</body>
</html>
Now that I posted this is just hit me that WP strips the <p>footer</p> out of the footer.php as well while injecting it's "powered by wordpress" snippet. I haven't enabled any WP theme support in the functions.php file yet as I haven't seen anyone doing anything like that before diving right into customizing their html.
UPDATE
I added the wp_body_open() function as suggested below by #amerinediary and my code still isn't rendering in the browser.
You're missing the wp_body_open() function.
Fire the wp_body_open action.
Which is getting triggered after the opening body tag, via the do_action( 'wp_body_open' ) hook.
Source # https://developer.wordpress.org/reference/functions/wp_body_open/
Following are default blank template part boiler plate
//header.php
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' );?>">
<?php wp_header(); ?>
</head>
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
//index.php
<?php get_header(); ?>
<?php get_footer(); ?>
//footer.php
<?php wp_footer(); ?>
</body>
</html>
Additionally <?php wp_footer(); ?> shouldn't be included inside a container as Wordpress is using it to render <script>'s tags.

wordpress get_header() on a page template getting the head content inside of the body tag

I am having trouble with my Wordpress template page. When calling get_header() in the template page, the content of the head is appearing inside the body tag and causing trouble. I couldn't find a solution for this.
This is what I mean :
page inspect element
page template :
<?php
/*
* Template Name: sub services
*/
get_header();
?>
<h1>sub page</h1>
<?php
get_footer();
?>
header.php :
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<?php wp_title();?>
<link rel="icon" type="image/png" href="/favicon.png">
<link href="https://fonts.googleapis.com/css2?family=Lemonada:wght#600&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/90928eb6b7.js" crossorigin="anonymous"></script>
<?php wp_head(); ?>
</head>
<body id="theme-body" <?php body_class(); ?>>
<header>
<h1>Main Header</h1>
</header>
and I have added a page in wordpress admin and linked it to the template.
wordpress add page
Everything works fine except that the content of the head is in the body tag. when calling get_header(). In the template.php I have checked my error log and its fine. I dont know what is causing this problem or what I'm doing something wrong.
Your header.php file contains the full body (including the closing </body>) and even the closing </html> tag. Your page template then appends to that some more HTML and a footer - that's invalid HTML and can't really be intended, is it?
Browser will probably try to fix those errors by adding missing or omitting superfluous tags, but in this case none of that will come up with the intended result - it will rather lead to a result like the one you are seeing.
The header.php file can contain the opening <body> tag, but not the closing </body>. But it should contain the Wordpress loop, and inside that the_content() to load the actual page content, and also the other WP functions to fetch heading, featured image etc.
After that, you usually fetch the footer using get_footer();, which might contain the closing </body> tag, if that's not in the page template.
So, the biggest problem in your code are the closing </body> and </html> tags and the resulting invalid HTML.

PHP header.php not connecting to a subfolder

Many of the connections with CSS is in my header.php file. For example, in the header.php file:
<link href="css/style.css" rel="stylesheet">
I make a new subfolder, and all the PHP links are messed up. Expected. So I change this:
<?php include("/includes/header.php"); ?>
to this:
<?php include("../includes/header.php"); ?>
And it's working! But, all PHP links in the header.php aren't working - such as my style.css.
How do I fix this?

Cherry Framework Child Theme - blank custom page template

I'm using a child theme that uses Cherry Framework.
I would like a custom page template that is completely blank.
If I make a file called "blank-template.php" and put it /wp-content/themes/my-child-theme/ with the following code.
<?php
/**
Template Name: Blank Template
*/
?>
<html>
<head>
</head>
<body>
test
</body>
</html>
If I then make a new page in Wordpress, and select this template and load the page, I expect to see a blank page however I see a page that has my theme header and footer with the words "test" in middle, as per my file.
Am I missing a step to make a fully custom template that ignores my themes header and footer?
get_header(); and get_footer(); are missing.
<?php
/**
Template Name: Blank Template
*/
?>
<html>
<head>
<?php get_header();?>
</head>
<body>
test
</body>
<?php get_footer(); ?>
</html>
For more details : http://www.templatemonster.com/help/wordpress-how-to-create-a-child-theme-based-on-cherry-framework.html

Categories