Skip to content

Instantly share code, notes, and snippets.

@levnhub
Last active July 31, 2018 15:12
Show Gist options
  • Save levnhub/301f4d53a54225fa6e8e55cb5aaed496 to your computer and use it in GitHub Desktop.
Save levnhub/301f4d53a54225fa6e8e55cb5aaed496 to your computer and use it in GitHub Desktop.
WP Functions & Hooks
<?php
/**
* The main functions file
*
*/
// Убираем лишнее
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
remove_action( 'wp_head', 'profile_link' );
// Подключаем jQuery
add_action( 'wp_enqueue_scripts', 'jQuery_scripts', 1 );
function jQuery_scripts() {
// Отменяем зарегистрированный jQuery
// Вместо "jquery-core", можно вписать "jquery", тогда будет отменен еще и jquery-migrate
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array(), '3.2.1', true );
wp_register_script( 'jquery-migrate', '//code.jquery.com/jquery-migrate-1.4.1.js', array(), '1.4.1', true );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-migrate' );
}
// Подключем стили и скрипты
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
// add_action('wp_print_styles', 'theme_name_scripts'); // можно использовать этот хук он более поздний
function theme_name_scripts() {
// Стили
wp_enqueue_style( 'style', get_stylesheet_uri() );
wp_enqueue_style( 'vendor-style', get_template_directory_uri() . '/css/vendor.min.css', array(), '1.0.0' );
wp_enqueue_style( 'main-style', get_template_directory_uri() . '/css/style.min.css', array(), '1.0.0' );
// Скрипты
wp_enqueue_script( 'vendor-script', get_template_directory_uri() . '/js/vendor.min.js', array(), '1.0.0', true );
wp_enqueue_script( 'main-script', get_template_directory_uri() . '/js/script.min.js', array(), '1.0.0', true );
}
// Убираем аттрибут type у script и styles
add_filter('style_loader_tag', 'myplugin_remove_type_attr', 10, 2);
add_filter('script_loader_tag', 'myplugin_remove_type_attr', 10, 2);
function myplugin_remove_type_attr($tag, $handle) {
return preg_replace( "/type=['\"]text\/(javascript|css)['\"]/", '', $tag );
}
// Добавляем поддержку меню
add_theme_support( 'menus' );
// Регистрируем меню (как вариант для wp_nav_menu())
add_action('after_setup_theme', function(){
register_nav_menus( array(
'header_menu' => 'Меню в шапке',
'footer_menu' => 'Меню в подвале'
) );
});
// Добавляем протоколы для меню
function ss_allow_skype_protocol( $protocols ){
$protocols[] = 'skype';
$protocols[] = 'tg';
$protocols[] = 'viber';
return $protocols;
}
add_filter( 'kses_allowed_protocols' , 'ss_allow_skype_protocol' );
// Включение поддержки миниатюр для всех типов постов
*/
add_theme_support( 'post-thumbnails' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment