HEX
Server: Apache/2.4.62 (Debian)
System: Linux plxsite 6.8.0-47-generic #47-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 27 21:40:26 UTC 2024 x86_64
User: root (0)
PHP: 8.1.30
Disabled: NONE
Upload Files
File: //proc/7575/cwd/wp-content/themes/polygant_2025/functions.php
<?php
/**
 * polugant_by_chernikova functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package polugant_by_chernikova
 */

if ( ! defined( '_S_VERSION' ) ) {
	// Replace the version number of the theme on each release.
	define( '_S_VERSION', '1.0.6' );
}

@ini_set( 'upload_max_size' , '128M' );
@ini_set( 'post_max_size', '128M');
@ini_set( 'max_execution_time', '300' );

// add_filter('wpcf7_load_js','__return_false');
// add_filter('wpcf7_load_css','__return_false');

/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function polugant_by_chernikova_setup() {
	/*
		* Make theme available for translation.
		* Translations can be filed in the /languages/ directory.
		* If you're building a theme based on polugant_by_chernikova, use a find and replace
		* to change 'polugant_by_chernikova' to the name of your theme in all the template files.
		*/
	load_theme_textdomain( 'polugant_by_chernikova', get_template_directory() . '/languages' );

	// Add default posts and comments RSS feed links to head.
	add_theme_support( 'automatic-feed-links' );

	/*
		* Let WordPress manage the document title.
		* By adding theme support, we declare that this theme does not use a
		* hard-coded <title> tag in the document head, and expect WordPress to
		* provide it for us.
		*/
	add_theme_support( 'title-tag' );

	/*
		* Enable support for Post Thumbnails on posts and pages.
		*
		* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		*/
	add_theme_support( 'post-thumbnails' );

	// This theme uses wp_nav_menu() in one location.
	register_nav_menus(
		array(
			'Primary menu' => esc_html__( 'Primary menu', 'polugant_by_chernikova' ),
			'Development of Fintech Apps and Services' => esc_html__( 'Development of Fintech Apps and Services', 'polugant_by_chernikova' ),
			'Marketing for Fintech and Crypto Projects' => esc_html__( 'Marketing for Fintech and Crypto Projects', 'polugant_by_chernikova' ),
			'Mobile Applications Development' => esc_html__( 'Mobile Applications Development', 'polugant_by_chernikova' ),
			'Marketmaking for Crypto Projects' => esc_html__( 'Marketmaking for Crypto Projects', 'polugant_by_chernikova' ),
			'Artificial Intelligence' => esc_html__( 'Artificial Intelligence', 'polugant_by_chernikova' ),
			'menu-6' => esc_html__( 'Menu 5', 'polugant_by_chernikova' ),
		)
	);
	

	/*
		* Switch default core markup for search form, comment form, and comments
		* to output valid HTML5.
		*/
	add_theme_support(
		'html5',
		array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
			'style',
			'script',
		)
	);

	// Set up the WordPress core custom background feature.
	add_theme_support(
		'custom-background',
		apply_filters(
			'polugant_by_chernikova_custom_background_args',
			array(
				'default-color' => 'ffffff',
				'default-image' => '',
			)
		)
	);

	// Add theme support for selective refresh for widgets.
	add_theme_support( 'customize-selective-refresh-widgets' );

	/**
	 * Add support for core custom logo.
	 *
	 * @link https://codex.wordpress.org/Theme_Logo
	 */
	add_theme_support(
		'custom-logo',
		array(
			'height'      => 250,
			'width'       => 250,
			'flex-width'  => true,
			'flex-height' => true,
		)
	);
}
add_action( 'after_setup_theme', 'polugant_by_chernikova_setup' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function polugant_by_chernikova_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'polugant_by_chernikova_content_width', 640 );
}
add_action( 'after_setup_theme', 'polugant_by_chernikova_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function polugant_by_chernikova_widgets_init() {
	register_sidebar(
		array(
			'name'          => esc_html__( 'Sidebar', 'polugant_by_chernikova' ),
			'id'            => 'sidebar-1',
			'description'   => esc_html__( 'Add widgets here.', 'polugant_by_chernikova' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);
}

add_action( 'widgets_init', 'polugant_by_chernikova_widgets_init' );

/**
 * Enqueue scripts and styles.
 */
function polugant_by_chernikova_scripts() {
	wp_enqueue_style( 'polugant_by_chernikova-style', get_stylesheet_uri(), array(), _S_VERSION );
	wp_style_add_data( 'polugant_by_chernikova-style', 'rtl', 'replace' );

	wp_enqueue_script( 'polugant_by_chernikova-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
	//wp_enqueue_style( 'pl-dop-style', get_template_directory_uri() . '/dop-style.css', array(), /*time()*/ _S_VERSION );
}
add_action( 'wp_enqueue_scripts', 'polugant_by_chernikova_scripts' );

/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.php';

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require get_template_directory() . '/inc/template-functions.php';

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

/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
	require get_template_directory() . '/inc/jetpack.php';
}

 

    function return_canon () {
        $canon_page = get_pagenum_link(1);
        return $canon_page;
    }

    function canon_paged() {
        if (is_paged()) {
            add_filter( 'wpseo_canonical', 'return_canon' );
        }
    }
    add_filter('wpseo_head','canon_paged');

    if ( ! function_exists( 'wp_add_page_number' ) )
    {
        function wp_add_page_number( $s )
        {
            global $page;
            $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
            ! empty ( $page ) && 1 < $page && $paged = $page;
            if( get_locale() == 'ru_RU' ){
                $paged > 0 && $s .= ''. sprintf( __( '' ), $paged );
            }else{
                $paged > 0 && $s .= ''. sprintf( __( '' ), $paged );
            }

            return $s;
        }
        add_filter( 'wpseo_metadesc', 'wp_add_page_number', 100, 1 );
    }

    // include_once "widgets/widget.php";

    add_action('admin_head', 'my_custom_fonts');

    function my_custom_fonts() {
        echo '<style>
    #adminmenu li.wp-menu-separator {
      margin: 0;
      height: auto;
    } 
    #adminmenu div.separator{
        height: auto;
    }
  </style>';
    }

    function edit_admin_menus() {
        global $menu;
   
        remove_submenu_page('edit.php', 'edit-tags.php?taxonomy=post_tag');
        // remove_menu_page( 'edit.php?post_type=acf-field-group' );          //Comments
        remove_menu_page( 'edit-comments.php' );          //Comments
        $menu[5][0] = 'Services'; // Изменить название
        $menu[5][6] = 'dashicons-welcome-write-blog'; // Изменить название
    }
    add_action( 'admin_menu', 'edit_admin_menus' );

    add_action('after_setup_theme', function(){
        register_nav_menus( array(
            'main_menu' => 'Главное меню'
        ) );

    });


## заменим слово «записи» на «статьи»
//$labels = apply_filters( "post_type_labels_{$post_type}", $labels );
add_filter('post_type_labels_post', 'rename_posts_labels');
function rename_posts_labels( $labels ){
	
	$new = array(
		'name'                  => 'Fintech apps',
	
		'menu_name'             => 'Fintech apps',
	);

	return (object) array_merge( (array) $labels, $new );
}

    function my_manage_columns( $columns ) {
        unset( $columns['tags'], $columns['comments']);
        return $columns;
    }

    function my_column_init() {
        add_filter( 'manage_posts_columns' , 'my_manage_columns' );
    }

    add_action( 'admin_init' , 'my_column_init' );

    function remove_dashboard_widgets() {
        global $wp_meta_boxes;

        unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
        unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
        unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
        unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
        unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']);
        unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
        unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
        unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);

    }

    add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );


    add_filter('script_loader_tag', 'add_defer_animated', 10, 2);
    function add_defer_animated($tag, $handle)
    {
        if ('animated-custom-plugin' !== $handle)
            return $tag;
        return str_replace(' src', ' defer src', $tag);
    }


 

    /**
     * Theme support
     */
    add_theme_support('title-tag');
    // add_theme_support('widgets');
    add_theme_support( 'post-thumbnails' );
    add_image_size( 'dev', 150, 200 );


    /**
     * Get first permalink
     * @return mixed
     */
    function get_first_post()
    {
        $loop = get_posts(array(
            'numberposts' => 1,
            'order' => 'DESC'
        ));
        $link = $loop[0]->ID;
        return $link;
    }

    /**
     * Get last permalink
     * @return mixed
     */
    function get_last_post($post_type = '')
    {
        $loop = get_posts(array(
            'suppress_filters' => false,
            'post_type' => $post_type,
            'numberposts' => 1,
            'order' => 'ASC'
        ));
        $link = $loop[0]->ID;
        return $link;
    }


 

    /**
     * WPML customize
     */
    /*
    function icl_post_languages($position = 'header') {
        $languages = icl_get_languages('skip_missing=1');
        $active = '';
        $other = '';

        if ($position !== 'header') {
            if (1 < count($languages)) {

                foreach ($languages as $l) {

                    if (!$l['active']) {
                        $other .= '<li><a href="' . $l['url'] . '">' . $l['translated_name'] . '</a></li>';
                    }

                }

                echo '<ul>' . $other . '</ul>';
            }
        } else {
            if (1 < count($languages)) {

                foreach ($languages as $l) {

                    if ($l['active']) {
                        $active .= '<dt><a id="langTarget" href="' . $l['url'] . '"><span class="flag" style="background-image:url(' . $l['country_flag_url'] . ')">'.$l['native_name'].'</span></a></dt>';
                    } else {
                        $other .= '<li><a href="' . $l['url'] . '"><span class="flag" style="background-image:url(' . $l['country_flag_url'] . ')">'.$l['native_name'].'</span></a></li>';
                    }

                }

                echo '<dl class="dropdown">' . $active . '<dd><ul id="langsBox">' . $other . '</ul></dd></dl>';
            }
        }
    }
    */


    /**
     * Crete BLOG post type
     */
    add_action('init', 'poly_register_blog_post_types');
    function poly_register_blog_post_types()
    {
        register_post_type('blog', array(
            'labels' => array(
                'name' => __('Blog'),
                'singular_name' => __('Blog'),
                'add_new' => __('Add new'),
                'add_new_item' => __('Add new post'),
                'edit_item' => __('Edit post'),
                'new_item' => __('New post'),
                'view_item' => __('View post'),
                'search_items' => __('Search post'),
                'not_found' => __('Post is not found'),
                'not_found_in_trash' => __('Not found post in trash'),
                'parent_item_colon' => '',
                'menu_name' => __('Blog')

            ),
          'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'has_archive' => true,
            'hierarchical' => false,
            'menu_position' => 10,
            'menu_icon' => 'dashicons-open-folder',
            'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'author')
        ));

        register_post_type('developers', array(
            'labels' => array(
                'name' => __('Developers'),
                'singular_name' => __('Developers'),
                'add_new' => __('Add new'),
                'add_new_item' => __('Add new post'),
                'edit_item' => __('Edit post'),
                'new_item' => __('New post'),
                'view_item' => __('View post'),
                'search_items' => __('Search post'),
                'not_found' => __('Post is not found'),
                'not_found_in_trash' => __('Not found post in trash'),
                'parent_item_colon' => '',
                'menu_name' => __('  -> Developers')
            ),
 'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'has_archive' => true,
            'hierarchical' => false,
            'menu_position' => 7,
            'menu_icon' => 'dashicons-welcome-write-blog',
            'supports' => array('title', 'editor', 'thumbnail', 'author')
        ));

     
      
      
		
		
		
	
		
		
      
		
		
		
        register_post_type('skills', array(
            'labels' => array(
                'name' => __('Hire developer'),
                'singular_name' => __('Skills'),
                'add_new' => __('Add new'),
                'add_new_item' => __('Add new post'),
                'edit_item' => __('Edit post'),
                'new_item' => __('New post'),
                'view_item' => __('View post'),
                'search_items' => __('Search post'),
                'not_found' => __('Post is not found'),
                'not_found_in_trash' => __('Not found post in trash'),
                'parent_item_colon' => '',
                'menu_name' => __('Hire developer')
            ),
             'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'has_archive' => true,
            'hierarchical' => false,
            'menu_position' => 6,
            'menu_icon' => 'dashicons-welcome-write-blog',
            'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'author')
        ));

 

        register_post_type('cases', array(
            'labels' => array(
                'name' => __('cases'),
                'singular_name' => __('case'),
                'add_new' => __('Add new'),
                'add_new_item' => __('Add new post'),
                'edit_item' => __('Edit post'),
                'new_item' => __('New post'),
                'view_item' => __('View post'),
                'search_items' => __('Search post'),
                'not_found' => __('Post is not found'),
                'not_found_in_trash' => __('Not found post in trash'),
                'parent_item_colon' => '',
                'menu_name' => __('Cases')
            ),
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'has_archive' => true,
            'hierarchical' => false,
            'menu_position' => 8,
            'menu_icon' => 'dashicons-open-folder',
			  'taxonomies'         => array( 'category' ),
            'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'author')
        ));

        register_post_type('reviews', array(
            'labels' => array(
                'name' => __('reviews'),
                'singular_name' => __('review'),
                'add_new' => __('Add new'),
                'add_new_item' => __('Add new post'),
                'edit_item' => __('Edit post'),
                'new_item' => __('New post'),
                'view_item' => __('View post'),
                'search_items' => __('Search post'),
                'not_found' => __('Post is not found'),
                'not_found_in_trash' => __('Not found post in trash'),
                'parent_item_colon' => '',
                'menu_name' => __('Reviews')
            ),
             'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'has_archive' => true,
            'hierarchical' => false,
            'menu_position' => 9,
            'menu_icon' => 'dashicons-open-folder',
				  'taxonomies'         => array( 'category' ),
            'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'author')
        ));



        register_taxonomy(
            'skill',
            'developers',
            array(
                'label' => __( 'Skills' ),
                'rewrite' => array( 'slug' => 'skill' ),
                'hierarchical' => false,
            )
        );
    }


    /**
     * Filter post pagination
     */
    add_action('navigation_markup_template', 'poly_sanitize_pagination');
    function poly_sanitize_pagination($content)
    {
        // Remove role attribute
        $content = str_replace('role="navigation"', '', $content);

        // Remove h2 tag
        $content = preg_replace('#<h2.*?>(.*?)</h2>#si', '', $content);

        return $content;
    }



    add_action( 'admin_init', 'my_remove_menu_pages' );
    function my_remove_menu_pages() {
        global $user_ID;
        if ( current_user_can( 'author' ) ) {
            remove_menu_page('edit.php'); // Записи
            remove_menu_page('index.php'); // Дашборд
            remove_menu_page('link-manager.php'); // Ссылки
            remove_menu_page('edit-comments.php'); // Комментарии
            remove_menu_page('edit.php?post_type=page'); // Страницы
            remove_menu_page('plugins.php'); // Плагины
            remove_menu_page('upload.php'); // Картинки
            remove_menu_page('themes.php'); // Внешний вид
            remove_menu_page('users.php'); // Пользователи
            remove_menu_page('tools.php'); // Инструменты
            remove_menu_page('options-general.php'); // Параметры
            remove_menu_page( 'authorhreview' );
        }
    }


    function true_block_admin_pages_redirect() {
        global $pagenow;
        // тут перечисляем в массиве страницы, которые хотим скрыть, я например закрыл весь раздел меню "Плагины"
        $pages_to_block = array(
            'plugins.php',
            'plugin-install.php',
            'plugin-editor.php',
            'link-manager.php',
            'edit-comments.php',
            'themes.php',
            'users.php',
            'tools.php',
            'options-general.php'
        );
        if(in_array($pagenow, $pages_to_block)){
            // указываем URL, на который будем перенаправлять тех, у кого нет доступа, в данном случае - главная страница админки
            wp_redirect( admin_url('/') );
            exit;
        }
    }
   




    
function wpexplorer_remove_menus() {
  
}
add_action( 'admin_menu', 'wpexplorer_remove_menus' );











function kama_excerpt( $args = '' ){
	global $post;

	if( is_string($args) )
		parse_str( $args, $args );

	$rg = (object) array_merge( array(
		'maxchar'     => 350,   // Макс. количество символов.
		'text'        => '',    // Какой текст обрезать (по умолчанию post_excerpt, если нет post_content.
								// Если в тексте есть `<!--more-->`, то `maxchar` игнорируется и берется
								// все до <!--more--> вместе с HTML.
		'autop'       => true,  // Заменить переносы строк на <p> и <br> или нет?
		'save_tags'   => '',    // Теги, которые нужно оставить в тексте, например '<strong><b><a>'.
		'more_text'   => 'Читать дальше...', // Текст ссылки `Читать дальше`.
		'ignore_more' => false, // нужно ли игнорировать <!--more--> в контенте
	), $args );

	$rg = apply_filters( 'kama_excerpt_args', $rg );

	if( ! $rg->text )
		$rg->text = $post->post_excerpt ?: $post->post_content;

	$text = $rg->text;
	// убираем блочные шорткоды: [foo]some data[/foo]. Учитывает markdown
	$text = preg_replace( '~[([a-z0-9_-]+)[^]]*](?!().*?[/1]~is', '', $text );
	// убираем шоткоды: [singlepic id=3]. Учитывает markdown
	$text = preg_replace( '~[/?[^]]*](?!()~', '', $text );
	$text = trim( $text );

	// <!--more-->
	if( ! $rg->ignore_more  &&  strpos( $text, '<!--more-->') ){
		preg_match('/(.*)<!--more-->/s', $text, $mm );

		$text = trim( $mm[1] );

		$text_append = ' <a href="'. get_permalink( $post ) .'#more-'. $post->ID .'">'. $rg->more_text .'</a>';
	}
	// text, excerpt, content
	else {
		$text = trim( strip_tags($text, $rg->save_tags) );

		// Обрезаем
		if( mb_strlen($text) > $rg->maxchar ){
			$text = mb_substr( $text, 0, $rg->maxchar );
			$text = preg_replace( '~(.*)s[^s]*$~s', '1...', $text ); // кил последнее слово, оно 99% неполное
		}
	}

	// сохраняем переносы строк. Упрощенный аналог wpautop()
	if( $rg->autop ){
		$text = preg_replace(
			array("/r/", "/n{2,}/", "/n/",   '~</p><br ?/?>~'),
			array('',     '</p><p>',  '<br />', '</p>'),
			$text
		);
	}

	$text = apply_filters( 'kama_excerpt', $text, $rg );

	if( isset($text_append) )
		$text .= $text_append;

	return ( $rg->autop && $text ) ? "<p>$text</p>" : $text;
}


  remove_action('wp_head', 'print_emoji_detection_script', 7);
  remove_action('wp_print_styles', 'print_emoji_styles');
  remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  remove_action( 'admin_print_styles', 'print_emoji_styles' );

remove_action('wp_head', 'wp_generator');


add_action( 'pre_get_posts', 'true_event_posts_per_page' );
function true_event_posts_per_page( $query ) {
 
	if ( ! is_admin() && $query->is_main_query() && is_post_type_archive( 'cases' )  ) {
		$query->set( 'posts_per_page', 999 );
	}
}

/* Add Schema */
add_action( 'wp_head', 'bb_head_article_schema' );
function bb_head_article_schema() {
    if (is_singular('post')) {
        ob_start(); 
    ?>
        <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "Article",
        "name": "<?php echo get_the_title(); ?>",
        "headline": "<?php echo get_the_title(); ?>",
        <?php 
        $descr = get_the_excerpt();
        if ( $descr ){
            ?>
            "description": "<?php echo $descr; ?>",
            <?php
        }
        ?>
        "url": "<?php echo get_page_link(); ?>",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "<?php echo get_page_link(); ?>"
        },
        "dateCreated": "<?php echo get_the_date('c'); ?>",
        "datePublished": "<?php echo get_the_date('c'); ?>",
        "dateModified": "<?php echo get_post_modified_time('c'); ?>",
        <?php if ( has_post_thumbnail(get_the_ID()) ) { ?>
        "thumbnailUrl": "<?php echo get_the_post_thumbnail_url(get_the_ID(), 'full'); ?>",
        "image": "<?php echo get_the_post_thumbnail_url(get_the_ID(), 'full'); ?>",
        <?php } ?>
        "author": {
            "@type": "Person",
        <?php
            $author = get_the_author();
        ?>
        "name": "<?php echo $author; ?>"
        },
        "publisher": {
            "@type": "Organization",
            "name": "Polygant",
            "logo": {
                "@type": "ImageObject",
                "url": "https://polygant.net/wp-content/themes/polygant_2023/img/logopoly.svg",
                "width": 257,
                "height": 65
            }
        }       
    }
    </script>
        <?php $out = ob_get_contents();
        ob_end_clean(); 
        echo $out;
    } else if (is_singular('blog')) {
        ob_start(); 
    ?>
        <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "BlogPosting",
        "name": "<?php echo get_the_title(); ?>",
        "headline": "<?php echo get_the_title(); ?>",
        <?php 
        $descr = get_the_excerpt();
        if ( $descr ){
            ?>
            "description": "<?php echo $descr; ?>",
            <?php
        }
        ?>
        "url": "<?php echo get_page_link(); ?>",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "<?php echo get_page_link(); ?>"
        },
        "dateCreated": "<?php echo get_the_date('c'); ?>",
        "datePublished": "<?php echo get_the_date('c'); ?>",
        "dateModified": "<?php echo get_post_modified_time('c'); ?>",
        <?php if ( has_post_thumbnail(get_the_ID()) ) { ?>
        "thumbnailUrl": "<?php echo get_the_post_thumbnail_url(get_the_ID(), 'full'); ?>",
        "image": "<?php echo get_the_post_thumbnail_url(get_the_ID(), 'full'); ?>",
        <?php } ?>
        "author": {
            "@type": "Person",
        <?php
            $author = get_the_author();
        ?>
        "name": "<?php echo $author; ?>"
        },
        "publisher": {
            "@type": "Organization",
            "name": "Polygant",
            "logo": {
                "@type": "ImageObject",
                "url": "https://polygant.net/wp-content/themes/polygant_2023/img/logopoly.svg",
                "width": 257,
                "height": 65
            }
        }       
    }
    </script>
        <?php $out = ob_get_contents();
        ob_end_clean(); 
        echo $out;
    }
}

add_action( 'wp_enqueue_scripts', 'disable_plugin_css', 9999 );
function disable_plugin_css() {
    $target_css = '/wp-content/plugins/ajax-search-lite/css/style-simple-red.css';

    global $wp_styles;
    foreach ( $wp_styles->queue as $handle ) {
        $src = $wp_styles->registered[$handle]->src;
        
        if ( strpos( $src, $target_css ) !== false ) {
            wp_dequeue_style( $handle );
            wp_deregister_style( $handle );
        }
    }
}

add_action( 'wp_enqueue_scripts', 'my_deregister_styles', 100 );
function my_deregister_styles() {
    if(!is_user_logged_in()) {  
        wp_deregister_style( 'dashicons' );
    }
}

/* Custom shortcode for VK VIDEO */
function vk_video_shortcode($atts) {
    $atts = shortcode_atts(
        array(
            'video_id' => '', // ID видео на YouTube
        ),
        $atts,
        'youtube_video'
    );

    if (empty($atts['video_id'])) {
        return 'Не указан ID видео YouTube.';
    }

    // Генерируем уникальный ID для контейнера
    $container_id = 'youtube-video-' . wp_rand();

    // Формируем URL для вставки. Обратите внимание: autoplay=1 убран, чтобы не конфликтовать с нашей логикой.
    $embed_src = 'https://www.youtube.com/embed/' . esc_attr($atts['video_id']);

    // Формируем HTML
    $html = '<div id="' . $container_id . '" class="responsive-video-wrapper">';
    
    // Блок-плейсхолдер
    $html .= '<div class="youtube-video-poster">';
    $html .= '<div class="video-loading-indicator"></div>'; // Индикатор загрузки
    $html .= '</div>';
    
    // Блок с iframe (изначально скрыт)
    $html .= '<iframe class="youtube-video-iframe" src="' . $embed_src . '" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen style="display: none;"></iframe>';
    
    $html .= '</div>'; // Закрываем .responsive-video-wrapper

    // Добавляем инлайн-скрипт для обработки загрузки
    $html .= "
    <script>
    document.addEventListener('DOMContentLoaded', function() {
        var container = document.getElementById('" . $container_id . "');
        if (container) {
            var poster = container.querySelector('.youtube-video-poster');
            var iframe = container.querySelector('.youtube-video-iframe');
            
            // Показываем плейсхолдер сразу
            poster.style.display = 'block';
            
            // Событие загрузки iframe
            iframe.addEventListener('load', function() {
                // Плавное переключение: скрываем плейсхолдер и показываем видео
                setTimeout(function() {
                    poster.style.opacity = '0';
                    setTimeout(function() {
                        poster.style.display = 'none';
                        iframe.style.display = 'block';
                    }, 500); // Время должно совпадать с CSS-переходом
                }, 300);
            });
            
            // Fallback: если видео по каким-то причинам не загрузилось, скрываем плейсхолдер через 5 сек.
            setTimeout(function() {
                if (poster.style.display !== 'none') {
                    poster.style.opacity = '0';
                    setTimeout(function() {
                        poster.style.display = 'none';
                        iframe.style.display = 'block';
                    }, 500);
                }
            }, 5000);
        }
    });
    </script>
    ";

    return $html;
}
add_shortcode('yt_video', 'vk_video_shortcode');