0

I need to create custom header for my WordPress theme. But I need to do it via plugin. Something like I have prebuild header in my plugin. I need to set it to header and I need to remove theme default header.

I research everywhere but I couldn't find any resource for this.

1
  • So you come here to point out something you need to do in the hope that someone will do it for you? Commented Apr 14, 2024 at 20:21

1 Answer 1

0

Please use the below code to load the header from plugin.

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();
});
Sign up to request clarification or add additional context in comments.

1 Comment

It worked. But it removed all of the head links such as scripts and styling sheets

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.