vic4884
1/14/2019 - 8:49 AM

Example #1 functions.php

<?php 

	/*
		С помощью этой функции вы можете установить максимально допустимую ширину для любого медиа в теме, например картинки, видео
	*/
	if ( ! isset( $content_width ) )
    $content_width = 800; /* pixels */
	/*----------------------------

				пример работы хука

		----------------------------*/
		// создадим функцию для хука - события
		//function echo_1(){ echo 1; }

		// привяжем функцию к хуку
		//add_action( 'my_hook', 'echo_1' );

		// выполним хук
		//do_action('my_hook'); //> выведет 1

	if ( ! function_exists( 'student_theme_setup' ) ) ://проверка на дубликат

	function student_theme_setup() {
		add_theme_support( 'automatic-feed-links' );
		/*----------------------------

				поддержка миниатюр постов

		----------------------------*/
		add_theme_support( 'post-thumbnails' );
	}

	endif;//function_exists(
	add_action( 'after_setup_theme', 'student_theme_setup' );

		/*----------------------------

								excerpt();

		----------------------------*/
		/*Меняет длину цитаты*/
		add_filter( 'excerpt_length', function(){
			return 20 ;
		} );
		/*Удаляем многоточие вконце цитаты [...]*/
		function new_excerpt_more($more) {
			return '...';
		}
		add_filter('excerpt_more', 'new_excerpt_more');
		/*----------------------------

						скрипты и стили

		----------------------------*/
		function student_theme_scripts() {
			wp_enqueue_style( 'style', get_stylesheet_uri(), false, time() );
			wp_enqueue_style( 'superfish', get_template_directory_uri() . '/assets/css/superfish.css',false,'1.1');
			wp_enqueue_style( 'superfish-vertical', get_template_directory_uri() . '/assets/css/superfish-vertical.css',false,'1.1');
			wp_enqueue_style( 'megafish', get_template_directory_uri() . '/assets/css/megafish.css',false,'1.1');
			wp_enqueue_style( 'superfish-navbar', get_template_directory_uri() . '/assets/css/superfish-navbar.css',false,time()); 
			wp_enqueue_style( 'lightbox-style', get_template_directory_uri() . '/assets/css/lightbox.css',false);
			

			wp_enqueue_script( 'script', get_template_directory_uri() . '/assets/js/script.js', array ( 'jquery' ), 1.2, true);
			wp_enqueue_script( 'hoverIntent', get_template_directory_uri() . '/assets/js/hoverIntent.js', array ( 'jquery' ), 1.2, true);
			wp_enqueue_script( 'superfish', get_template_directory_uri() . '/assets/js/superfish.js', array ( 'jquery' ), 1.2, true);
			wp_enqueue_script( 'supersubs', get_template_directory_uri() . '/assets/js/supersubs.js', array ( 'jquery' ), 1.2, true);
			wp_enqueue_script("jquery-ui-tooltip", array('jquery'));//включить отдельный компонент встроенный в ядро - всплывающие подсказки
			wp_enqueue_script( 'lightbox', get_template_directory_uri() . '/assets/js/lightbox.js', array ( 'jquery' ), 1.1, true);




			if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {//включить комментарии 
	      wp_enqueue_script( 'comment-reply' );
	    }
		}
		add_action( 'wp_enqueue_scripts', 'student_theme_scripts' );
		/*----------------------------

		пример моей функции - какая страница

		----------------------------*/
		function wtf(){
			if(is_front_page()){
				echo "front_page";
			}
			if(is_singular()){
				echo "singular / ";
			}
			if(is_page()){
				echo "page";
			}
			if(is_404 ()){
				echo "404";
			}
		}
		/*----------------------------

		кастомные типы записей

		----------------------------*/
		require get_template_directory() . '/inc/movie-post-type.php';
		/*----------------------------

		кастомные таксономии

		----------------------------*/
		require get_template_directory() . '/inc/movie-taxonomy.php';
		/*----------------------------

		 "Изображение заголовка"

		----------------------------*/
		function student_theme_custom_header_setup() {
	    $args = array(
	        //'default-image'      => get_template_directory_uri() . '/assets/img/256x256.png',
	        'default-text-color' => '000',
	        'width'              => 100,
	        'height'             => 100,
	        'flex-width'         => false,
	        'flex-height'        => false,
	    );
		  add_theme_support( 'custom-header', $args );
		}
		/*----------------------------

		 "Свойства сайта - Выбрать логотип"

		----------------------------*/
		function student_theme_custom_logo_setup() {
	    $defaults = array(
	        'height'      => 100,
	        'width'       => 100,
	        'flex-height' => false,
	        'flex-width'  => false,
	        'header-text' => array( 'site-title', 'site-description' ),
	    );
		    add_theme_support( 'custom-logo', $defaults );
		}
		add_action( 'after_setup_theme', 'student_theme_custom_header_setup' );
		add_action( 'after_setup_theme', 'student_theme_custom_logo_setup' );

		/*----------------------------

		 			Регистрация сйдбара

		----------------------------*/
		function student_theme_widgets_init() {
	    register_sidebar( array(
	        'name'          => 'Главный сайдбар', 'student_theme' ,
	        'id'            => 'sidebar-1',
	        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
	        'after_widget'  => '</aside>',
	        'before_title'  => '<h3 class="widget-title">',
	        'after_title'   => '</h3>',
	    ) );
	 
	    register_sidebar( array(
	        'name'          => __( 'Нижний сайдбар', 'student_theme' ),
	        'id'            => 'sidebar-2',
	        'before_widget' => '<ul><li id="%1$s" class="widget %2$s">',
	        'after_widget'  => '</li></ul>',
	        'before_title'  => '<h3 class="widget-title">',
	        'after_title'   => '</h3>',
	    ) );
		}
		add_action( 'widgets_init', 'student_theme_widgets_init' );

		/*----------------------------

						Кастомнй виджет

		----------------------------*/
		require get_template_directory() . '/inc/custom-widget.php';
		/*----------------------------

						Регистрация меню

		----------------------------*/
		require get_template_directory() . '/inc/custom-menus.php';
		/*----------------------------

						Кастомайзер

		----------------------------*/
		//require get_template_directory() . '/inc/customizer.php';

		/*----------------------------

		Добавляет класс в body если это домашняя страница

		----------------------------*/
		function wporg_css_body_class($classes){
		    if (is_home()) {
		        $classes[] = 'blablabla';
		    }
		    return $classes;
		}
		add_filter('body_class', 'wporg_css_body_class');
		/*----------------------------

		Пишет каждый acton

		----------------------------*/
		function wporg_debug(){
		    echo '<p>' . current_action() . '</p>';
		}
		//add_action('all', 'wporg_debug');
		/*----------------------------

		Фильтр дописывает -s--o после заголовка

		----------------------------*/
		function change__titile($content){
			$new_content = $content . ' -s--o';
			return $new_content;
		}
		//add_filter('the_title','change__titile');

		/*----------------------------

		Фильтр $x

		----------------------------*/
		function vic_function( $x ) {
			$x = '<strong>' . $x . '</strong>'; // если переменная текстовая, мы просто сделали текст жирным шрифтом
			return $x; // возвращаем
		}
		add_filter( 'vic_filter', 'vic_function' );






		/*----------------------------

		---

		----------------------------*/