I am using a child theme. In my child theme folder I have the following files:
In my custom page template "page-lp3.php" I'm using get_header('blank') to call a custom header template. But no matter what I do, it reverts to the child-theme's header.php file not header-blank.php as intended.
This is the code in "page-lp3.php":
<?php
/*
Template Name: LP3
*/
get_header('blank');
?>
The custom template is activated for that page in WordPress. And the changes I make to the custom template are working as expected. But the custom header is not cooperating. What am I doing wrong?
Check the error logs files of your project and removes errors first.
I think you do something wrong inside the "header-blank.php"
How to debugging error
1 . Call default header if that come copy default header code into your new header-black.php and check.
2. add die with some message inside new header file and check
3 remove cache of browser
Related
I created a page using elementor(named as: 'Error-page'), currently using linoor theme. What I want is to load this 'Error-page' via theme's default 404.php file (NOT using any plugin). Should I just type in 'include Error-page.php' in 404.php file to make it work?
Meta: My goal is to show my custom error page which I created using elementor(named as: Error-page) when invalid url is typed. One way of doing it is using plugin(I prefer not to do this for the time being), 2nd way could be somehow including this custom page in theme's default 404.php file
Note: Im new to wordpress
after thinking about your question, i have 2 solutions for you:
1. if you do not have code knowledge
This way is simple and safer, but have limits than other way - it's not using your template but redirect viewer to your template page. Any way, the same result
Build the 404 template with Elementor and publish it
Open your theme's 404.php file
In the very first top of the template file **(below <?php tag) paste this code:
wp_redirect( '/your-template-slug' );
exit;
Save it and you're done
2. If you have basic code knowledge:
This way is a litle complex, but it alow you to using not for 404 file - but other templates (archive, categories...)
Install "Anywhere Elementor" plugin
Build the 404 template as you do with Elementor
Get your template php shortcode
Edit the theme's 404.php file to echo out your template
In case you need more detail guide, i have record a step by step guide video here
My theme doesn't support custom headers when trying via a plugin so i was wondering if there was another way around this?
Tested WP Header Images by adding some code in header.php, but doesn't seem to work.
Tried the plugin Unique Headers, but it pops a message that the theme doesn't provide custom header when activating it.
By default, there is the same header for every WordPress page of the site. But how to call different header in WordPress? For that, create a new header-your page.php file i.e create a header file for the page you want a different header. Suppose you want a different header on about page. Create a header-about.php file and keep it in the Theme folder.
Then, go in page template file say page.php and replace the header code with
<?php
if(is_page(about))
{
get_header('about');
}
else
{
get_header();
}
wp_head();
?>
You can see, is_page is used to check the page id for “about” page. The function get_header is used for calling a new header file. Simply, the above code is informing WordPress that if someone opens the page, which is ‘about’ then WordPress will display a file called header-about.php if it is existing. If not, then WordPress will render the default header file.
This way, you can call different WordPress headers on different pages.
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 have a custom page template built in a child theme and I need to call out a custom header.
I have template-home.php page template calling out
<?php get_header('home'); ?>
for the header.
I have a saved wp-header-home.php with a little custom button that I need to get.
The page template is unsuccessful at calling out the custom header-home, rather it's calling out the default wp-header.php. I can see when I add my changes into that file, they're reflected.
So, what's going on? Why does my
<?php get_header('home'); ?>
not work to get the wp-header-home.php? What am I doing wrong?
This is the site in question: http://va.northwaydesigns.com
Create the file with header-home.php
I need to include a custom PHP page in Wordpress.
So what I need to do is just to show this custom php page using the Wordpress theme installed on that Wordpress.
Does not mind which theme is up, the custom php page will have to be shown under any theme is installed in that moment.
How do I do it in Wordpress?
I am new to Wordpress development.
Thanks
Creating a custom php page that will be able to be viewed in any theme (and have the theme applied) would be considerably difficult.
Each wordpress page calls specific theme functions of that particular theme, as well as referencing files of that theme to generate header, footer, css files, javascript files, etc.. Your custom page would need to plan for all of these contingencies, for each possible theme used.
Here's a alternative solution: inject PHP code directly into a standard wordpress page via this plugin http://wordpress.org/extend/plugins/allow-php-in-posts-and-pages/
Meaning: you make a normal wordpress page, but are able to add php to it. When this page is rendered, the proper page template is used, and all the theme references are taken care of for you.
You could do this easily with a page template. WordPress allows you to create page templates which can be assigned to a page via the 'Page Attributes' panel within the page editor. These templates are php files inside your theme directory which begin with some code like (see this page in The Codex for more info):
<?php
/*
Template name: Custom PHP Page
*/
?>
<?php // begin custom PHP page ?>
Typically a template is a variation on the regular theme files (such as page.php) and would call the get_header() and get_footer() functions and have an instance of the loop. However if you simply want to use a custom PHP page, then all you need to do is create the file you want inside the current theme directory and add the above code at the very top of the file.
To output the custom PHP page on your site, you would need to add a new page via the admin area and then assign your new page template to this page.
Alternatively, if you want to include a custom PHP page inside an existing theme file, you use the code:
<?php include(TEMPLATEPATH . '/includes/file.php'); ?>
in this case your custom PHP file would be located inside a directory called 'includes' within your current theme directory.
Tim.
It's not that difficult. Here's what you need:
Once you include the main wordpress blog header, the entire armamentarium of wordpress functions is available to you, which allows you to get the active theme's directory. Once you get that, just include the header and the footer of the theme.
// If title is not displayed before loading the header, Wordpress displays "Page not found" as the title
echo "<head>
<title>Your page title</title>
</head>";
// Include the Main Wordpress blog header
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";
//Now, you need to get the active theme's folder, and get a relative path to that folder
$homeurl=home_url();
$ddir= get_bloginfo( 'template_directory');
$current_theme_relative_path=substr_replace($ddir, "", 0, strlen($homeurl));
//echo "<br/>The relative path to the currently active theme is ".$current_theme_relative_path;
//Once you have the path, include the header and footer, adding your custom php code in between.
// Include the specific theme header you need
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/header.php";
// Your custom PHP code STARTS here
// Add anything you want to display to the user
echo "
<h2>
Your form has been submitted
</h2>";
// END of custom code
?>
<?php
}
// Now end with the theme's footer
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/footer.php";
?>
Was very helpfull (even if dated of 2011-13)
Also, as a thank you, i'm sharing the version i made
it's usefull if your wordpress folder is not located at ROOT
PasBin Link - wordpress custom php page
just change the value of $wplocalpath in :
// Wordpress path (if wordpress is not located at ROOT
// $wplocalpath="/Wordpress1";