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.
Related
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.
I have a custom WP page and want to be able to target different page id classes. When I add body_class() to the header <body> section it outputs all classes to the page!
I also have a gtag Google Analytics script tag at the start of the header but I don't think that should affect it.
<!DOCTYPE html>
<html>
<head>
<meta name="google-site-verification" content="Ey9SSwK6cHm5KMRuCUinWcWx1URGF8FZ8FV5HnG2B4A" />
<?php wp_head(); ?>
<title>The Carnivore Diet - The Ultimate Diet for Weight loss, Digestion and Inflammation!</title>
</head>
<body>
<?php body_class(); ?>>
The answer was I had to have body_class() in the body tag:
<body <?php body_class(); ?>>
I am creating my first website from scratch and had seen something where you can reduce code by using PHP includes for sections of the site that are to be repeated. So far, I have a head.php (which I added due to my stylesheet.css being linked there and needing access to it on every page), header.php, footer.php, index.php, and other pages with the php extension (about, contact, that bunch).
Everything is appearing where I'd like it to except for one issue: when setting the body background color, everything (all includes: header.php, footer.php) seems to be in the body. I tested this by setting a border around the body, and it confirmed what I thought.
Does anyone have an idea what is going wrong? I am using flexbox in my header, footer, and other bits within the index file, but I don't think that should be affecting anything.
<!DOCTYPE html>
<?php include 'head.php'; ?>
<?php include 'header.php'; ?>
<body id="main-block">
<!-- Button links to Portfolio and Other stuff -->
<div class="flex-container">
<a class="main-button" href="#">Web Work</a>
<a class="main-button" href="#">Other Work</a>
</div>
</body>
<?php include 'footer.php'; ?>
</html>
your body tag is suppose to wrap around your header and footer elements. see below markup
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<?php include (header);?>
<?php include (footer);?>
</body>
</html>
if u wanna change the background color of your elements just add css
element { background-color:pink }
I admit that I do not really understand your issue. But I'll give you a little snippet to start coding php:
<html>
<head>
<title>Welcome</title>
<style>
<?php include 'stile.php'; ?>
</style>
</head>
<body>
<?php include 'header.php'; ?>
<?php include 'footer.php'; ?>
</body>
</html>
I'm working on my first php site, I'm running into an issue I can't see to figure out. I'm trying to have one php page that contains my structure, and others that inject their html inside, while retaining url changes so I can still direct link pages.
So far this is what I'm doing, but it doesn't seem efficient:
index.php
<html xmlns="http://www.w3.org/1999/xhtml">
<?php include("head.php"); ?>
<body>
<div class="container">
<!-- Navigation header -->
<?php include("navigation.php"); ?>
<!-- Main container -->
<div id="MainContainer">
<?php include("home.php"); ?>
</div>
<!-- Footer -->
<?php include("footer.php"); ?>
</div>
</body>
</html>
about.php
<html xmlns="http://www.w3.org/1999/xhtml">
<?php include("head.php"); ?>
<body>
<div class="container">
<!-- Navigation header -->
<?php include("navigation.php"); ?>
<!-- Main container -->
<div id="MainContainer">
About me!
</div>
<!-- Footer -->
<?php include("footer.php"); ?>
</div>
</body>
</html>
This feels totally wrong, if I ever want to change my container class, or change the structure, I now have to do it in two places instead of one.
In ASP.net MVC I would have a Layout_Head.cshtml file that would contain my HTML structure and inside I can render views from different pages, the url changes but the layout is always rendered first and then the controller/actions take care of injecting the html of the needed views.
How do I replicate that in PHP?
Usually people use php includes for templating more like this:
header.php
<html>
<head>
<title></title>
</head>
<body>
<div class="container">
footer.php
</div> <!-- .container -->
</body>
</html>
about.php
<?php include('header.php'); ?>
... content goes here ...
<?php include('footer.php'); ?>
This is so you don't need to continuously repeat the start/end tags on every template you make.
ANSWER: Was a problem with web hosting.
This is my code
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="description" lang="en" content="Test Website " />
<meta name="author" content="">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title</title>
</head>
<body>
<section id="wrapper">
<?php include('includes/topHeader.php'); ?>
<?php include('includes/leftSide.php'); ?>
<?php include('includes/middleSide.php'); ?>
<?php include('includes/rightSide.php'); ?>
</section>
<?php include('includes/foot.php'); ?>
</section>
</body>
</html>
question the other php files not appear in the main page?
to create it I have use this website
http://www.1stwebdesigner.com/css/how-to-create-php-website-template/
Update
View Source shows:
<section id="wrapper">
<!--?php include('../includes/topHeader.php'); ?-->
<!--?php include('../includes/leftSide.php'); ?-->
<!--?php include('../includes/middleSide.php'); ?-->
<!--?php include('../includes/rightSide.php'); ?-->
</section>
<!--?php include('../includes/foot.php'); ?-->
You are using the include function right, so please make sure that:
Files you are trying to include really exists, you can test with file_exists function
You don't have any fatal errors somewhere in the files that stops the execution of your program (you can check error log)
Your markup is well formatted (in some cases when code is not formated correctly browsers cannot render the page correctly)
On a quick note apart from what was already suggested. Try
<?php include('../includes/topHeader.php'); ?>
<?php include('../includes/leftSide.php'); ?>
<?php include('../includes/middleSide.php'); ?>
<?php include('../includes/rightSide.php'); ?>
I say this with an assumption that the include folder resides above the current file in the folder structure.