I am having some issue with site I am developing. Let me know you some of the pages are static php pages which are working fine. But the issue is with wordpress pages, I have all css and js files are included from header-required.php file. I am calling this header-required.php file from function file by wp_head hook. here is my code of function.php file:
function hook_javascript()
{
include('http://'.$_SERVER['HTTP_HOST'].'/inc/header-required.php');
}
add_action('wp_head','hook_javascript');
And I am calling this function from all wordpress file code wp_head();
here is the code:
while loading, This function is calling properly, but it does not including file header-required.php. If i am including this file from specific wordpress file, Its working.
Please help. Thanks..
your specified path is correct. Actully I am calling this file from wordpress and header-required.php file is php file which is outside wordpress directory. example.com contain all static php pages, and inside this directory,I have created one another directory called wrpas, which contains wordpress. This some what confusing because i am using static php pages and wordpress together on one site. Another thing header and footer files are static php pages, which i am using in wordpres.
Thanks!!!
Put that file in theme folder
Rather than using php include use get_template_part for wordpress
Use
<?php get_template_part('header-required'); ?>
For more details
http://codex.wordpress.org/Function_Reference/get_template_part
Don't include through hook because this is php file, you can directly include through include and require function in your header.php file inside the theme.
Related
I am trying to do something simple but it won't work.
I have a custom Wordpress header. I need to include external php classes and other stuff. The problem is that if I do that the page breaks, it doesn't work anymore.
This doesn't occur when I try to "require" external php scripts inside page templates. The problem occurs when I include it in the header.
To make it shorter, I have:
header-home.php (standard wordpress theme header file, which has to include the following file)
snippets.php (a php class)
header.home.php is located at /wp-content/themes/twentyseventeen-child/templates...
snippets.php is located at /resources/scripts/snippets.php
Perhaps the header loads something that is not compatible with custom inclusions?
I was able to include an external php file which contains pure html elements. If I try to load custom classes, the page simply breaks. The include filepath is correct, so that's not the problem.
All the files that you are going to require, you must do in the file "functions.php" that is in "/wp-content/themes/twentyseventeen-child/functions.php", then in the file "header.php" you can instantiate your objects or call functions. For example:
Functions.php
<?php
require("./YourClass.php");
function getYourClass() {
$yourClass = new YourClass();
var_dump($yourClass); //Verify if it returns data and then delete this line
return $yourClass;
}
Header.php
getYourClass();//Here it brings the object and shows the output.
I tried to include some php files in header.php. I use the script below :-
get_template_part( 'custom/tos_functions');
However get_template_part doesn't work for me, so I use include which works fine.
include (TEMPLATEPATH . "custom/tos_functions.php");
The issue is, if I put this line in header.php, I want to use some of the functions in custom template , say profile.php. In profile.php the file is as though not being called at all. I can't get the data I need in profile.php.
Then I tried to take out the include script from header, and place it in profile.php and the data I need can be called perfectly fine.
This will be an issue as there will be many custom php pages I need to create, thus every page will call the include script.
Question, why is it that the file cannot be called from header.php ? The data can only be retrieved within header.php and any custom page that calls the header, couldn't get the data from the include file.
Anyway I can fix this so that I can place the include file in the header.php?
Thank you!
Rather than including files in the theme template files (such as header.php), you should include them in the theme's functions.php file.
Including them in the template files is almost always too late in the WP run for it to be useful, and it may cause unexpected results and unexpected output in your templates.
Instead, in your functions.php file, do something like so:
require_once 'custom/tos_functions.php';
Then, your API code is available where you need it, and it is in the "right" place and consistent with the "WordPress way".
When I use get_header(); in index.php, it automatically load the header.php file and and need not to include anything in the page.
Generally index.php is the main page. everything should be include there before it was called. Am I wrong?
It seems you are checking index.php inside the theme. But that is not the entry point to the site, but the index.php file in the wordpress root. There you can see it has included some files and inside those they have included some other files. Like wise file including functions are written in the wordpress core codes. So, you don't want to worry about including files in your theme. if you call get_header() function, the function itself has coded so that the relevant file to be included. If you are going to use a separate file to code functionality other than standard wordpress theme files, you'll have to include it at the top of functions.php
I have been searching all day to figure this out and still cant find an answer. I want to take the header of my wordpress site and have its own file (headerstandalone.php). I want it to do all the functions and calling it needs to do without being in the same directory as the standard header.php. Is this possible?
I am basically trying to implement it into some custom pages.
Would this help you with your problem?
<?php include_once("headerstandalone.php"); ?>
I would put the headerstandalone.php in a seperate directory, be sure to include wp-load.php in your standalone file so you can use all your functions and then include that file in your main header using require_once(../another_directory/headerstandalone.php).
If you don't want to include the file in you header then you could add the standaloneheader.php code to a function and add it to either your own plugin's function file or the themes function file and call that function in the header.
The first line of index.php is get_header();
There is no include / require in my index.php. yet the wordpress site continues to render the head section of home page by referring get_header() from general-template.php
How is wordpress framework achieving this?
get_header() is a function located in wp-includes/general-template.php.
This function includes the header.php template file from your current theme's directory.
If your theme contains no header.php file then this function includes the header file located in wp-includes/theme-compat/header.php.
You can find more information about this function in codex of Wordpress.org
The index.php you're referring to is the index off your theme. Within the root folder of your WP installation also an index.php is located. This is the first one called and starts the whole 'trip'.
http://theme.fm/wp-content/uploads/2011/09/wordpress-internals-how-wordpress-boots-up-382x600.png shows an image of the complete file load-sequence.