Dodanie własnego stylu dla podstron w WordPressie.
W miejsce zapisane WERSALIKAMI wpisujemy własną nazwę stylu, który wrzucamy do katalogu naszego szablonu. W ostatnim przykładzie wpisujemy dodatkowo nazwę własnej strony, utworzonej w php, jeżeli taką stronę posiadamy. Od teraz podstrony – archiwum, kategorii, pojedynczego wpisu – posiadają własny plik CSS.
Pojedynczy wpis:
function register_single_style() {
if ( is_single() ) {
wp_enqueue_style( 'single', get_stylesheet_directory_uri() . '/STYL.css' );
}
}
add_action( 'wp_enqueue_scripts', 'register_single_style' );
Strona archiwów:
function register_archive_style() {
if ( is_archive() ) {
wp_enqueue_style( 'archive', get_stylesheet_directory_uri() . '/STYL.css' );
}
}
add_action( 'wp_enqueue_scripts', 'register_archive_style' );
Strona statyczna:
function register_page_style() {
if ( is_page() ) {
wp_enqueue_style( '', get_stylesheet_directory_uri() . '/STYL.css' );
}
}
add_action( 'wp_enqueue_scripts', 'register_page_style' );
Własna strona:
function register_NAZWA STRONY_style() {
if ( is_page( 'NAZWA STRONY') ) {
wp_enqueue_style( 'NAZWA STRONY', get_stylesheet_directory_uri() . '/STYL.css' );
}
}
add_action( 'wp_enqueue_scripts', 'register_NAZWA STRONY_style' );