Поддержка Темы и шаблоны Добавление своих стилей через functions.php

  • Доброго времени суток форумчане, подскажите пожалуйста, пытаюсь создать свои стили через functions.php но получаю ошибку
    Fatal error: Cannot redeclare stroy_scripts() (previously declared in E:\server\install\OpenServer\domains\stroy.tpl\wp-content\themes\stroy\functions.php:4) in E:\server\install\OpenServer\domains\stroy.tpl\wp-content\themes\stroy\functions.php on line 3
    Код у меня такой

    function stroy_scripts() {
        wp_enqueue_style( 'stroy-style', get_stylesheet_uri() );
        wp_enqueue_style('stroy-style', get_template_directory_uri() . '/css/template.css');
    }
    add_action('wp_enqueue_scripts', 'stroy_scripts');

    WordPress только начал изучать и пока разобраться сложно

Просмотр 5 ответов — с 1 по 5 (всего 5)
  • пытаюсь создать свои стили через functions.php

    зачем? количество файлов стилей нужно сокращать, а не плодить.

    Cannot redeclare stroy_scripts()

    Такое может быть, если функцию stroy_scripts() объявляют дважды.

    В строке:

    
    wp_enqueue_style('stroy-style', get_template_directory_uri() . '/css/template.css');
    

    stroy-style попробуйте поменять на что-то более уникальное, например stroy-style-template.

    Не помогает. вот весь мой functions.php

    <?php
    
    function stroy_scripts() {
      wp_enqueue_style( 'stroy-style', get_stylesheet_uri() );
        wp_enqueue_style('stroy-style-template', get_template_directory_uri() . '/css/template.css');
    }
    add_action('wp_enqueue_scripts', 'stroy-style-template');
    
    remove_action( 'wp_head', 'wp_resource_hints', 2 );
    remove_action('wp_head', 'wp_generator');
    ?>

    Получаю

    Fatal error: Cannot redeclare stroy_scripts() (previously declared in E:\server\install\OpenServer\domains\stroy.tpl\wp-content\themes\stroy\functions.php:4) in E:\server\install\OpenServer\domains\stroy.tpl\wp-content\themes\stroy\functions.php on line 3

    • Ответ изменён 1 год, 8 месяцев назад пользователем stasweb.

    вот весь мой functions.php

    Попробуйте так

    
    <?php
    
    function stroy_scripts() {
     wp_enqueue_style( 'stroy-style', get_stylesheet_uri() );
     wp_enqueue_style('stroy-style-template', get_template_directory_uri() . '/css/template.css');
    }
    
    add_action('wp_enqueue_scripts', 'stroy_scripts');
    
    remove_action( 'wp_head', 'wp_resource_hints', 2 );
    remove_action('wp_head', 'wp_generator');
    
    

    Не работает

    <?php
    /*
    function stroy_scripts() {
      wp_enqueue_style( 'stroy-style', get_stylesheet_uri() );
        wp_enqueue_style('stroy-style-template', get_template_directory_uri() . '/css/template.css');
    }
    add_action('wp_enqueue_scripts', 'stroy-style-template');
    */
    function stroy_scripts() {
    	wp_enqueue_style( 'stroy-style', get_stylesheet_uri() );
    	wp_enqueue_style('stroy-style-template', get_template_directory_uri() . '/css/template.css');
       }
       add_action('wp_enqueue_scripts', 'stroy_scripts');
    
    // меню
    register_nav_menus(
    	array(
    		'head_menu' => 'Шапка сайта',
    		'side_menu' => 'Левый сайдбар'
    	)
    );
    
    remove_action( 'wp_head', 'wp_resource_hints', 2 );
    remove_action('wp_head', 'wp_generator'); 
    ?>

    ошибка
    Fatal error: Cannot redeclare stroy_scripts() (previously declared in E:\server\install\OpenServer\domains\stroy.tpl\wp-content\themes\stroy\functions.php:10) in E:\server\install\OpenServer\domains\stroy.tpl\wp-content\themes\stroy\functions.php on line 9

Просмотр 5 ответов — с 1 по 5 (всего 5)
  • Тема «Добавление своих стилей через functions.php» закрыта для новых ответов.