通过插件的 WordPress 自定义标头

问题描述 投票:0回答:1

我需要为我的 WordPress 主题创建自定义标头。但我需要通过插件来完成。就像我的插件中有预构建头一样。我需要将其设置为标题,并且需要删除主题默认标题。

我到处研究,但找不到任何资源。

wordpress wordpress-plugin-creation
1个回答
0
投票

请使用以下代码从插件加载标头。

add_action('get_header', function(){
    require PLUGIN_DIR.'includes/templates/header.php';
    $templates   = [];
    $templates[] = 'header.php';
    remove_all_actions( 'wp_head' );
    ob_start();
    locate_template( $templates, true );
    ob_get_clean();
});
© www.soinside.com 2019 - 2024. All rights reserved.