简体   繁体   中英

How do I get my current wordpress theme's header & footer in a PHP file?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM