Skip to content

Instantly share code, notes, and snippets.

@slavapas
Created January 14, 2021 18:59
Show Gist options
  • Save slavapas/39dd356dda682f2ffbecb9eecec43374 to your computer and use it in GitHub Desktop.
Save slavapas/39dd356dda682f2ffbecb9eecec43374 to your computer and use it in GitHub Desktop.
standart functions.php with varialbes PATH
<?php
// define constant
define('PS_THEME_ROOT', get_template_directory_uri());
define('PS_CSS_DIR', PS_THEME_ROOT . '/assets/css');
define('PS_JS_DIR', PS_THEME_ROOT . '/assets/js');
define('PS_IMG_DIR', PS_THEME_ROOT . '/assets/img');
// правильный способ подключить стили и скрипты
add_action('wp_enqueue_scripts', 'theme_name_scripts');
// add_action('wp_print_styles', 'theme_name_scripts'); // можно использовать этот хук он более поздний
function theme_name_scripts()
{
// register styles
wp_register_style('css-bootstrap', PS_CSS_DIR . '/bootstrap.min.css', [], false, 'all');
wp_register_style('css-slick', PS_CSS_DIR . '/slick.css', [], false, 'all');
wp_register_style('css-slick-theme', PS_CSS_DIR . '/slick-theme.css', ['css-slick'], false, 'all');
// register scripts
wp_register_script('js-slick', PS_JS_DIR . '/slick.js', [], '1.0.0', true);
// ---------------------
// enqueue styles
wp_enqueue_style('css-bootstrap');
wp_enqueue_style('css-slick');
wp_enqueue_style('css-slick-theme');
wp_enqueue_style('style-name', get_stylesheet_uri());
// enqueue scripts
wp_enqueue_script('js-slick');
// wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/$examplejs', array($DEPENDENCY), '1.0.0', $TRUE_or_FAULSE );
}
// hook after theme setup parameters
add_action('after_theme_setup', function () {
add_theme_support('post-thumnails');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment