下面是我如何将自定义页眉和页脚添加到自定义插件的。
plugin.php:
function _get_header($name, $require_once = TRUE, $args = []) {
return load_template(dirname(__FILE__) . "/includes/{$name}.php", $require_once, $args);
}
function _get_footer($name, $require_once = TRUE, $args = []) {
return load_template(dirname(__FILE__) . "/includes/{$name}.php", $require_once, $args);
}
Create your templates:
/includes/my-header.php
/includes/my-footer.php
在模板文件中,例如。
single-custom.php:
_get_header(\'my-header\'); //<- name of file without extension.
_get_footer(\'my-footer\'); //<- name of file without extension.
以下是WP的二十二个文件:
标题:https://github.com/WordPress/WordPress/blob/master/wp-content/themes/twentytwentyone/header.php页脚:https://github.com/WordPress/WordPress/blob/master/wp-content/themes/twentytwentyone/footer.php