N
N
Nik Faraday2021-08-10 14:41:37
WordPress
Nik Faraday, 2021-08-10 14:41:37

Connect styles for different header?

I’ve been sitting on WordPress for a few days, so don’t scold me, I can’t find information anywhere, I don’t even know how to correctly formulate a request in google ...

The page header page-header.php (For example) uses different styles than home-header .php To include styles on home-header.php, a function like myTheme_assets is used via wp_enqueue_style/script (File fucntion.php), but on home-header it is searched automatically when I use the wp_head function (For footer, also wp_footer) , but how find it and connect it to page-home.php? After all, what is the right way to call this function?

I know function/file names matter a lot, so this question is here too

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2021-08-10
@NikFaraday

wp_enqueue_scriptsYou need to have the same logic for connecting scripts on the hook , which is used when connecting different header files

function add_theme_scripts() {
  if ( is_home() || is_front_page() ) {
    wp_enqueue_style( 'slyle-home', get_theme_file_uri( 'assets/css/slyle-home.min.css' ) );
  } else {
    wp_enqueue_style( 'slyle-page', get_theme_file_uri( 'assets/css/slyle-page.min.css' ) );
  }
}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );

Read more about this in the article: How to correctly include styles and scripts in WordPress?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question