Created
October 7, 2019 10:58
-
-
Save Glinkfr/8b157aa8140301c986e7e0fdc70d42a9 to your computer and use it in GitHub Desktop.
Fichier fonctions thème enfant Sparkling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* On enlève les scripts du thème parent | |
*/ | |
function sparkling_child_dequeue_script() { | |
wp_dequeue_script( 'sparkling_scripts' ); | |
} | |
add_action( 'wp_print_scripts', 'sparkling_child_dequeue_script()', 100 ); | |
/** | |
* On charge nos propre srcipts et styles. | |
*/ | |
function sparkling_child_scripts() { | |
// Add Bootstrap default CSS | |
wp_enqueue_style( 'sparkling-bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css' ); | |
// Add Font Awesome stylesheet | |
wp_enqueue_style( 'sparkling-icons', get_template_directory_uri() . '/assets/css/fontawesome-all.min.css', null, '5.1.1.', 'all' ); | |
// on ajoute les font google en leur ajoutant le paramètre display | |
$font = of_get_option( 'main_body_typography' ); | |
if ( isset( $font['subset'] ) ) { | |
wp_register_style( 'sparkling-fonts', '//fonts.googleapis.com/css?family=Open+Sans:400italic,400,600,700&display=swap|Roboto+Slab:400,300,700&display=swap&subset=' . $font['subset'] ); | |
} else { | |
wp_register_style( 'sparkling-fonts', '//fonts.googleapis.com/css?family=Open+Sans:400italic,400,600,700&display=swap|Roboto+Slab:400,300,700&display=swap' ); | |
} | |
wp_enqueue_style( 'sparkling-fonts' ); | |
// Add slider CSS only if is front page ans slider is enabled | |
if ( ( is_home() || is_front_page() ) && of_get_option( 'sparkling_slider_checkbox' ) == 1 ) { | |
wp_enqueue_style( 'flexslider-css', get_template_directory_uri() . '/assets/css/flexslider.css' ); | |
} | |
// On ne charge pas les styles du theme parent à cet endroit mais plus loin dans ce fichier | |
// wp_enqueue_style( 'sparkling-style', get_stylesheet_uri(), null, '2.4.2', 'all' ); | |
// Add Bootstrap default JS | |
wp_enqueue_script( 'sparkling-bootstrapjs', get_template_directory_uri() . '/assets/js/vendor/bootstrap.min.js', array( 'jquery' ) ); | |
if ( ( is_home() || is_front_page() ) && of_get_option( 'sparkling_slider_checkbox' ) == 1 ) { | |
// Add slider JS only if is front page ans slider is enabled | |
wp_enqueue_script( 'flexslider-js', get_template_directory_uri() . '/assets/js/vendor/flexslider.min.js', array( 'jquery' ), '20140222', true ); | |
// Flexslider customization | |
wp_enqueue_script( | |
'flexslider-customization', get_template_directory_uri() . '/assets/js/flexslider-custom.js', array( | |
'jquery', | |
'flexslider-js', | |
), '20140716', true | |
); | |
} | |
// Main theme related functions | |
wp_enqueue_script( 'sparkling-functions', get_template_directory_uri() . '/assets/js/functions.js', array( 'jquery' ), '20180503', false ); | |
// This one is for accessibility | |
wp_enqueue_script( 'sparkling-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.min.js', array(), '20140222', true ); | |
// Treaded comments | |
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { | |
wp_enqueue_script( 'comment-reply' ); | |
} | |
// Academicons | |
if ( of_get_option( 'academicons' ) == 1 ) { | |
wp_enqueue_style( 'academicons-css', get_template_directory_uri() . '/assets/css/academicons.min.css', null, '1.8.6', 'all' ); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'sparkling_child_scripts' ); | |
// On charge les styles parents et enfants | |
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 20); | |
function theme_enqueue_styles() { | |
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); | |
wp_dequeue_style('sparkling-style'); | |
wp_enqueue_style( 'child-style', | |
get_stylesheet_directory_uri() . '/style.css', | |
array('parent-style') | |
); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment