I decided to try building a theme without using a foundation like underscores etc... I have all the required files
(ss of files),
my functions.php file looks like this:
functions file,
and I am trying to load this file to enqueue all my css:
ss of enqueue-scripts file.
This has worked on other themes I did based off underscores so I assume I am missing some function that perhaps controls the pathing?
Added a message to console.log to see the pages were being loaded and on all of them I do get the message back, so I assume they must be pathing. Is there a way to check or set the get_template_directory_uri?
try this:
require __DIR__ . "/functions.php"
Thanks Gerald, was missing the wp_head
Related
The file is manually created by me & not a part of the theme.
I've tried by placing get_header( ) inside my file but it shows a error that get_header( ) is not defined.
Maybe you don't have default header and footer names. Then you need to set additional name.
Includes the header.php template file from your current theme's directory. If a name is specified then a specialised header header-{name}.php will be included.
If the theme contains no header.php file then the header from the
default theme wp-includes/theme-compat/header.php will be included.
Source: https://codex.wordpress.org/get_header
I highly discourage it but you need to include the wp-load.php file that resides in the root of your wordpress installation, in your lone php file. That is how you have access to WP functions and capabilities.
But again I HIGHLY DISCOURAGE IT. Find another way, create a simple plugin and activate it, in which you put that php file's code, or if part of a theme, just create a new page template with a different header, that you can call with get_header('name_of_header_without_php_extension') or a new footer called the same way but with get_footer().
There are alternatives, maybe if you share what you are trying to achieve, we can guide you to a better, safe solution.
Based on theme it's defer.
Same time define as get_header(),get_footer()
But now latest themse assign particular theme name based header & footer function
Ex: Theme Name is "Demo"
So the header function assign as Demo_get_header() or get_header_Demo()
Dashboard ->Appearance ->Editor -> in your Template file or in page.php write
<?php get_header()?>,<?php get_footer()?>
if you want to use different headers on different pages
1. create new file , name it header-example.php
2. you can call this header in any page using code
I can't seem to find any documentation on this so maybe someone here can help. I have been adding all my WooCommerce hooks to my functions.php file but I would rather have all of them in a separate file to keep things tidy. Obviously I will need another php file for these but how do I link it to the functions.php file so that the code runs as it does now? Thanks
just create new file with your woocommerce hooks code name anything what u want.
Ex. woocommercehook.php and place file in theme folder.
in function.php file just include your woocommercehook.php file at last.
include("woocommercehook.php");
Done. all work same as early.
The PHP include/include_once and require/require_once will work fine. However,
create another file with your hooks( woo-hooks.php ) and use WP get_template_directory to require the file.
require get_template_directory() . '/woo-hooks.php';
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".
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.
I have put some php code in a sidebar-01.php
i like in my template file to get that code
How do u do that ? (i don't what to change the code of WP for updating purpose)
i have try include('sidebar-01.php); - it don't work
i like to have a function like : get_header(); for my file, something like : get_file('sidebar-01')
is it possible ?
Go to the 'Theme Editor', look for sidebar.php. Edit it and place this code there:
include('sidebar-01.php');
Also, remember to place your sidebar-01.php in same folder as the other theme .php files (basically your theme folder).
Try the get_sidebar() function defined in wp-includes/general-template.php
If your sidebar file name is sidebar-home.php then call it like this
get_sidebar('home');