admin管理员组

文章数量:1125950

I'm currently trying to build my first classic theme. Unfortunately, I'm not sure how exactly I have to integrate the individual scripts into the functions.php.

I get the following error message:

Notice: The wp_enqueue_style function was called incorrectly. Scripts and styles should not be registered or included before the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. This notice was caused by the preload-style handle. Further information: Debugging in WordPress (English). (This message was added in version 3.3.0.)

Can someone maybe help me with this? The integration of the preload function is also the result of a few tutorials and a lot of Google - but unfortunately I can't get any further... :(

My functions.php:

<?php
require_once('customizer.php');



if ( ! function_exists( 'wpnoob_setup' ) ) :
    /**
     * 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 post thumbnails.
     */
    function wpnoob_setup() {
        
    /**
     * Make theme available for translation.
     * Translations can be placed in the /languages/ directory.
     */
        load_theme_textdomain( 'wpnoob', get_template_directory() . '/languages' );

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

        /**
         * Enable support for post thumbnails and featured images.
         */
        add_theme_support( 'post-thumbnails' );

        /**
         * Add support for two custom navigation menus.
         */
        register_nav_menus( array(
            'primary' => __( 'Primare Menu', 'wpnoob' ),
            'footer' => __( 'Footer Menu', 'wpnoob' ),
        'sidebar' => __('Sidebar Menu', 'wpnoob')
        ) );  


        /**
         * Enable support for the following post formats:
         * aside, gallery, quote, image, and video
         */
        add_theme_support( 'post-formats', array( 'aside', 'gallery', 'quote', 'image', 'video' ) );

        //theme-support

            
            add_theme_support('automatic-feed-links');
            add_theme_support( 'title-tag' ) ;
            add_theme_support('wp-block-styles');
            add_theme_support( 'align-wide' );
            add_theme_support( "responsive-embeds" );
            add_theme_support( "post-thumbnails" );
            add_theme_support( "title-tag" );
            add_theme_support( 'custom-logo', array(
                'height' => 70,
                'width'  => 70,
            ) );
            $custom_backgrounds_defaults = array(
                'default-color'          => '000000',
                'default-image'          => ''
              /*  'default-repeat'         => 'repeat',
                'default-position-x'     => 'left',
                    'default-position-y'     => 'top',
                    'default-size'           => 'auto',
                'default-attachment'     => 'scroll',
                'wp-head-callback'       => '_custom_background_cb',
                'admin-head-callback'    => '',
                'admin-preview-callback' => ''*/
            );
            add_theme_support( 'custom-background', $custom_backgrounds_defaults  );
          
            add_theme_support( 'html5', array( 'search-form' ) );
            add_theme_support( 'custom-spacing');
            add_theme_support( 'appearance-tools' );
            add_theme_support( 'post-formats',  array( 'aside', 'gallery', 'quote', 'image', 'video' ) );
            add_theme_support('core-block-patterns');
            add_theme_support( 'editor-styles' );
            add_editor_style('style-editor.css');

            function theme_slug_setup() { add_theme_support( 'title-tag' ); } add_action( 'after_setup_theme', 'theme_slug_setup' );

                //block-library-styles abschalten, betrieb dann mit classic-editor
                function gutenberg_style_abschalten() {
                    wp_dequeue_style( 'wp-block-library' ); }
                    add_action( 'wp_enqueue_scripts', 'gutenberg_style_abschalten', 100 );

                    // Emojis entfernen

                    function remove_emoji()
                    {
                    remove_action('wp_head', 'print_emoji_detection_script', 7);
                    remove_action('admin_print_scripts', 'print_emoji_detection_script');
                    remove_action('admin_print_styles', 'print_emoji_styles');
                    remove_action('wp_print_styles', 'print_emoji_styles');
                    remove_filter('the_content_feed', 'wp_staticize_emoji');
                    remove_filter('comment_text_rss', 'wp_staticize_emoji');
                    remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
                    add_filter('tiny_mce_plugins', 'remove_tinymce_emoji');
                    }


                    add_action('init', 'remove_emoji');
                    function remove_tinymce_emoji($plugins)
                    {
                    if (!is_array($plugins))
                        {
                        return array();
                        }
                    return array_diff($plugins, array(
                        'wpemoji'
                    ));
                    }



                // fix custo,izer ???

                add_filter('the_tags', 'wp32234_add_span_get_the_tag_list');

function wp32234_add_span_get_the_tag_list($list) {
    $list = str_replace('rel="tag">', 'rel="tag"><span>', $list);
    $list = str_replace('</a>', '</span></a>', $list);
    return $list;
}

                //remove_action('shutdown', 'wp_ob_end_flush_all', 1);


                //Sidebar 
                function wpnoob_widgets_init() {
                    register_sidebar( array(
                        'name'          => __( 'Primary Sidebar', 'wpnoob' ),
                        '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'          => __( 'Secondary Sidebar', 'wpnoob' ),
                        'id'            => 'sidebar-1',
                        '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', 'my_register_sidebars' );
                function my_register_sidebars() {
                    /* Register the 'primary' sidebar. */
                    register_sidebar(
                        array(
                            'id'            => 'sidebar-1',
                            'name'          => __( 'Primary Sidebar', 'wpnoob' ),
                            'description'   => __( 'Just a Sidebar. You can put a Menu in here.', 'wpnoob' ),
                            'before_widget' => '<div id="%1$s" class="widget %2$s">',
                            'after_widget'  => '</div>',
                            'before_title'  => '<h3 class="widget-title">',
                            'after_title'   => '</h3>',
                        )
                    );
                }
                /* Repeat register_sidebar() code for additional sidebars. */

                //Registrieren von Customizer-Funktionalität

                    function wpnoob_post_title( $heading, $post ) {
                        echo '<' . $heading . ' class="entry-title">';
                        if ( ! is_single() ) { ?>
                        <a href="<?php esc_url( the_permalink() ); ?>">
                        <?php }
                        the_title();
                        if ( ! is_single() ) { ?>
                        </a>
                        <?php }
                        echo '</' . $heading . '>';
                        }
                
                        function wpnoob_the_content() {
                        $text = _x( 'Continue reading “%s”', 's = post title', 'wpnoob' );
                        $more = sprintf( $text, esc_html( get_the_title() ) );
                        the_content( $more );
                        }

                // JS defer-Attribut setzen

                    add_filter( 'script_loader_tag', 'add_defer_attribute', 10, 2 );
                    function add_defer_attribute( $tag, $handle ) {
                        $scripts_to_defer = array( 'my-header-js', 'my-helper-js' );
                        
                        foreach( $scripts_to_defer as $defer_script )
                            if( $defer_script === $handle )
                                return str_replace( ' src', ' defer="defer" src', $tag );
                        
                        return $tag;
                    }
                
                //JS einbinden

                function themeslug_enqueue_helper_script() {
                        wp_enqueue_script( 'my-helper-js', get_stylesheet_directory_uri().'/js/dom-helper.js', false );
                    }
                    add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_helper_script' );
                    /* function themeslug_enqueue_header_script() {
                        wp_enqueue_script( 'my-header-js', get_stylesheet_directory_uri().'/js/header.js', false );
                    } */
                    function themeslug_enqueue_header_script() {
                        wp_enqueue_script( 'my-header-js', get_stylesheet_directory_uri().'/js/header.js', array(), null, true );
                    }
                    add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_header_script' );
                





                    //Tags & Categories
                    function add_taxonomies_to_pages() {     register_taxonomy_for_object_type( 'post_tag', 'page' );    register_taxonomy_for_object_type( 'category', 'page' );}add_action( 'init', 'add_taxonomies_to_pages' );  if ( ! is_admin() ) {       add_action( 'pre_get_posts', 'category_and_tag_archives' ); }function category_and_tag_archives( $wp_query ) {  $my_post_array = array('post','page');  if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) ) $wp_query->set( 'post_type', $my_post_array );  if ( $wp_query->get( 'tag' ) )  $wp_query->set( 'post_type', $my_post_array );}







                //funktionen für comment.php, author-link in den comments führt sonst auf die startseite
                function use_author_link_as_comment_author_url( $url, $id, $comment ) {
                    if ( $comment->user_id ) {
                        return get_author_posts_url( $comment->user_id );
                    }
                    return $url;
                }
                add_filter( 'get_comment_author_url', 'use_author_link_as_comment_author_url', 10, 3 );

                // excerpt_more should be set the empty.
                    add_filter( 'excerpt_more', '__return_empty_string', 21 );

                    function wpse_134143_excerpt_more_link( $excerpt ) {
                        $excerpt .= sprintf( 
                                '<a href="%s" class="cp-archives-read-more-link">%s</a>',
                                esc_url( get_permalink() ),
                                __( '...read more &nbsp;&raquo;', 'wpnoob' )
                        );
                        return $excerpt;
                    }
                    add_filter( 'the_excerpt', 'wpse_134143_excerpt_more_link', 21 );

                
                //archives ## hooks for wp_get_archives();
                
                
                function featured_image_support() {
                    add_theme_support( 'post-thumbnails' );
                }
                add_action( 'after_setup_theme', 'featured_image_support' );
            
                
                wp_enqueue_style('preload-style', get_stylesheet_uri(), false, null);
                add_filter( 'style_loader_tag',  'preload_filter', 10, 2 );
                function preload_filter( $html, $handle ){
                    if (strcmp($handle, 'preload-style') == 0) {
                        $html = str_replace("rel='stylesheet'", "rel='preload' as='style' ", $html);
                    }
                    return $html;
                }


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    }
endif; // wpnoob_setup
add_action( 'after_setup_theme', 'wpnoob_setup' );

If anyone wants to nudge me in the right direction, I'd be really happy!

I'm currently trying to build my first classic theme. Unfortunately, I'm not sure how exactly I have to integrate the individual scripts into the functions.php.

I get the following error message:

Notice: The wp_enqueue_style function was called incorrectly. Scripts and styles should not be registered or included before the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. This notice was caused by the preload-style handle. Further information: Debugging in WordPress (English). (This message was added in version 3.3.0.)

Can someone maybe help me with this? The integration of the preload function is also the result of a few tutorials and a lot of Google - but unfortunately I can't get any further... :(

My functions.php:

<?php
require_once('customizer.php');



if ( ! function_exists( 'wpnoob_setup' ) ) :
    /**
     * 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 post thumbnails.
     */
    function wpnoob_setup() {
        
    /**
     * Make theme available for translation.
     * Translations can be placed in the /languages/ directory.
     */
        load_theme_textdomain( 'wpnoob', get_template_directory() . '/languages' );

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

        /**
         * Enable support for post thumbnails and featured images.
         */
        add_theme_support( 'post-thumbnails' );

        /**
         * Add support for two custom navigation menus.
         */
        register_nav_menus( array(
            'primary' => __( 'Primare Menu', 'wpnoob' ),
            'footer' => __( 'Footer Menu', 'wpnoob' ),
        'sidebar' => __('Sidebar Menu', 'wpnoob')
        ) );  


        /**
         * Enable support for the following post formats:
         * aside, gallery, quote, image, and video
         */
        add_theme_support( 'post-formats', array( 'aside', 'gallery', 'quote', 'image', 'video' ) );

        //theme-support

            
            add_theme_support('automatic-feed-links');
            add_theme_support( 'title-tag' ) ;
            add_theme_support('wp-block-styles');
            add_theme_support( 'align-wide' );
            add_theme_support( "responsive-embeds" );
            add_theme_support( "post-thumbnails" );
            add_theme_support( "title-tag" );
            add_theme_support( 'custom-logo', array(
                'height' => 70,
                'width'  => 70,
            ) );
            $custom_backgrounds_defaults = array(
                'default-color'          => '000000',
                'default-image'          => ''
              /*  'default-repeat'         => 'repeat',
                'default-position-x'     => 'left',
                    'default-position-y'     => 'top',
                    'default-size'           => 'auto',
                'default-attachment'     => 'scroll',
                'wp-head-callback'       => '_custom_background_cb',
                'admin-head-callback'    => '',
                'admin-preview-callback' => ''*/
            );
            add_theme_support( 'custom-background', $custom_backgrounds_defaults  );
          
            add_theme_support( 'html5', array( 'search-form' ) );
            add_theme_support( 'custom-spacing');
            add_theme_support( 'appearance-tools' );
            add_theme_support( 'post-formats',  array( 'aside', 'gallery', 'quote', 'image', 'video' ) );
            add_theme_support('core-block-patterns');
            add_theme_support( 'editor-styles' );
            add_editor_style('style-editor.css');

            function theme_slug_setup() { add_theme_support( 'title-tag' ); } add_action( 'after_setup_theme', 'theme_slug_setup' );

                //block-library-styles abschalten, betrieb dann mit classic-editor
                function gutenberg_style_abschalten() {
                    wp_dequeue_style( 'wp-block-library' ); }
                    add_action( 'wp_enqueue_scripts', 'gutenberg_style_abschalten', 100 );

                    // Emojis entfernen

                    function remove_emoji()
                    {
                    remove_action('wp_head', 'print_emoji_detection_script', 7);
                    remove_action('admin_print_scripts', 'print_emoji_detection_script');
                    remove_action('admin_print_styles', 'print_emoji_styles');
                    remove_action('wp_print_styles', 'print_emoji_styles');
                    remove_filter('the_content_feed', 'wp_staticize_emoji');
                    remove_filter('comment_text_rss', 'wp_staticize_emoji');
                    remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
                    add_filter('tiny_mce_plugins', 'remove_tinymce_emoji');
                    }


                    add_action('init', 'remove_emoji');
                    function remove_tinymce_emoji($plugins)
                    {
                    if (!is_array($plugins))
                        {
                        return array();
                        }
                    return array_diff($plugins, array(
                        'wpemoji'
                    ));
                    }



                // fix custo,izer ???

                add_filter('the_tags', 'wp32234_add_span_get_the_tag_list');

function wp32234_add_span_get_the_tag_list($list) {
    $list = str_replace('rel="tag">', 'rel="tag"><span>', $list);
    $list = str_replace('</a>', '</span></a>', $list);
    return $list;
}

                //remove_action('shutdown', 'wp_ob_end_flush_all', 1);


                //Sidebar 
                function wpnoob_widgets_init() {
                    register_sidebar( array(
                        'name'          => __( 'Primary Sidebar', 'wpnoob' ),
                        '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'          => __( 'Secondary Sidebar', 'wpnoob' ),
                        'id'            => 'sidebar-1',
                        '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', 'my_register_sidebars' );
                function my_register_sidebars() {
                    /* Register the 'primary' sidebar. */
                    register_sidebar(
                        array(
                            'id'            => 'sidebar-1',
                            'name'          => __( 'Primary Sidebar', 'wpnoob' ),
                            'description'   => __( 'Just a Sidebar. You can put a Menu in here.', 'wpnoob' ),
                            'before_widget' => '<div id="%1$s" class="widget %2$s">',
                            'after_widget'  => '</div>',
                            'before_title'  => '<h3 class="widget-title">',
                            'after_title'   => '</h3>',
                        )
                    );
                }
                /* Repeat register_sidebar() code for additional sidebars. */

                //Registrieren von Customizer-Funktionalität

                    function wpnoob_post_title( $heading, $post ) {
                        echo '<' . $heading . ' class="entry-title">';
                        if ( ! is_single() ) { ?>
                        <a href="<?php esc_url( the_permalink() ); ?>">
                        <?php }
                        the_title();
                        if ( ! is_single() ) { ?>
                        </a>
                        <?php }
                        echo '</' . $heading . '>';
                        }
                
                        function wpnoob_the_content() {
                        $text = _x( 'Continue reading “%s”', 's = post title', 'wpnoob' );
                        $more = sprintf( $text, esc_html( get_the_title() ) );
                        the_content( $more );
                        }

                // JS defer-Attribut setzen

                    add_filter( 'script_loader_tag', 'add_defer_attribute', 10, 2 );
                    function add_defer_attribute( $tag, $handle ) {
                        $scripts_to_defer = array( 'my-header-js', 'my-helper-js' );
                        
                        foreach( $scripts_to_defer as $defer_script )
                            if( $defer_script === $handle )
                                return str_replace( ' src', ' defer="defer" src', $tag );
                        
                        return $tag;
                    }
                
                //JS einbinden

                function themeslug_enqueue_helper_script() {
                        wp_enqueue_script( 'my-helper-js', get_stylesheet_directory_uri().'/js/dom-helper.js', false );
                    }
                    add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_helper_script' );
                    /* function themeslug_enqueue_header_script() {
                        wp_enqueue_script( 'my-header-js', get_stylesheet_directory_uri().'/js/header.js', false );
                    } */
                    function themeslug_enqueue_header_script() {
                        wp_enqueue_script( 'my-header-js', get_stylesheet_directory_uri().'/js/header.js', array(), null, true );
                    }
                    add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_header_script' );
                





                    //Tags & Categories
                    function add_taxonomies_to_pages() {     register_taxonomy_for_object_type( 'post_tag', 'page' );    register_taxonomy_for_object_type( 'category', 'page' );}add_action( 'init', 'add_taxonomies_to_pages' );  if ( ! is_admin() ) {       add_action( 'pre_get_posts', 'category_and_tag_archives' ); }function category_and_tag_archives( $wp_query ) {  $my_post_array = array('post','page');  if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) ) $wp_query->set( 'post_type', $my_post_array );  if ( $wp_query->get( 'tag' ) )  $wp_query->set( 'post_type', $my_post_array );}







                //funktionen für comment.php, author-link in den comments führt sonst auf die startseite
                function use_author_link_as_comment_author_url( $url, $id, $comment ) {
                    if ( $comment->user_id ) {
                        return get_author_posts_url( $comment->user_id );
                    }
                    return $url;
                }
                add_filter( 'get_comment_author_url', 'use_author_link_as_comment_author_url', 10, 3 );

                // excerpt_more should be set the empty.
                    add_filter( 'excerpt_more', '__return_empty_string', 21 );

                    function wpse_134143_excerpt_more_link( $excerpt ) {
                        $excerpt .= sprintf( 
                                '<a href="%s" class="cp-archives-read-more-link">%s</a>',
                                esc_url( get_permalink() ),
                                __( '...read more &nbsp;&raquo;', 'wpnoob' )
                        );
                        return $excerpt;
                    }
                    add_filter( 'the_excerpt', 'wpse_134143_excerpt_more_link', 21 );

                
                //archives ## hooks for wp_get_archives();
                
                
                function featured_image_support() {
                    add_theme_support( 'post-thumbnails' );
                }
                add_action( 'after_setup_theme', 'featured_image_support' );
            
                
                wp_enqueue_style('preload-style', get_stylesheet_uri(), false, null);
                add_filter( 'style_loader_tag',  'preload_filter', 10, 2 );
                function preload_filter( $html, $handle ){
                    if (strcmp($handle, 'preload-style') == 0) {
                        $html = str_replace("rel='stylesheet'", "rel='preload' as='style' ", $html);
                    }
                    return $html;
                }


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    }
endif; // wpnoob_setup
add_action( 'after_setup_theme', 'wpnoob_setup' );

If anyone wants to nudge me in the right direction, I'd be really happy!

Share Improve this question edited Feb 21, 2024 at 10:57 Tom J Nowell 60.7k7 gold badges77 silver badges147 bronze badges asked Feb 21, 2024 at 10:52 glowbright77glowbright77 1 1
  • 1 You have to do it on that specific hook, but it looks like you've nested functions inside eachother which is very bad and makes life a lot harder, any line that starts with function that has a name should generally be in the top level of the file, not inside the body of another function. Right now you're calling wp_enqueue_style directly inside wpnoob_setup, and that function runs on the after_setup_theme hook which is incorrect. The error message you posted is telling you which hook you're supposed to use when calling wp_enqueue_style and wp_enqueue_script – Tom J Nowell Commented Feb 21, 2024 at 11:00
Add a comment  | 

2 Answers 2

Reset to default 0

you are trying to enqueue stylesheets before wp_enqueue_scripts hook is fired. WordPress recommends registering and enqueuing scripts and styles on the wp_enqueue_scripts hook to ensure they are loaded correctly.

In your functions.php, you are enqueueing the stylesheet preload-style using the wp_enqueue_style function outside the wp_enqueue_scripts action hook, causing the error. To resolve this, you need to move the wp_enqueue_style call inside the wp_enqueue_scripts action hook

add_action('wp_enqueue_scripts', 'wpnoob_enqueue_styles');

function wpnoob_enqueue_styles() {
    wp_enqueue_style('preload-style', get_stylesheet_uri(), false, null);
    add_filter('style_loader_tag', 'wpnoob_preload_filter', 10, 2);
}

function wpnoob_preload_filter($html, $handle) {
    if ($handle === 'preload-style') {
        $html = str_replace("rel='stylesheet'", "rel='preload' as='style'", $html);
    }
    return $html;
}

I removed the white screen and put the functions in the hook. No error message. But unfortunately I can't set a "preload" attribute in the for the style.css.

How do you do this correctly?

my current functions.php:

    <?php
require_once('customizer.php');



if ( ! function_exists( 'wpnoob_setup' ) ) :
    /**
     * 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 post thumbnails.
     */
    function wpnoob_setup() {
        
    /**
     * Make theme available for translation.
     * Translations can be placed in the /languages/ directory.
     */
        load_theme_textdomain( 'wpnoob', get_template_directory() . '/languages' );

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

        /**
         * Enable support for post thumbnails and featured images.
         */
        add_theme_support( 'post-thumbnails' );

        /**
         * Add support for two custom navigation menus.
         */
        register_nav_menus( array(
            'primary' => __( 'Primare Menu', 'wpnoob' ),
            'footer' => __( 'Footer Menu', 'wpnoob' ),
        'sidebar' => __('Sidebar Menu', 'wpnoob')
        ) );  


        /**
         * Enable support for the following post formats:
         * aside, gallery, quote, image, and video
         */
        add_theme_support( 'post-formats', array( 'aside', 'gallery', 'quote', 'image', 'video' ) );

        //theme-support

            
            add_theme_support('automatic-feed-links');
            add_theme_support( 'title-tag' ) ;
            add_theme_support('wp-block-styles');
            add_theme_support( 'align-wide' );
            add_theme_support( "responsive-embeds" );
            add_theme_support( "post-thumbnails" );
            add_theme_support( "title-tag" );
            add_theme_support( 'custom-logo', array(
                'height' => 70,
                'width'  => 70,
            ) );
            $custom_backgrounds_defaults = array(
                'default-color'          => '000000',
                'default-image'          => ''
              /*  'default-repeat'         => 'repeat',
                'default-position-x'     => 'left',
                    'default-position-y'     => 'top',
                    'default-size'           => 'auto',
                'default-attachment'     => 'scroll',
                'wp-head-callback'       => '_custom_background_cb',
                'admin-head-callback'    => '',
                'admin-preview-callback' => ''*/
            );
            add_theme_support( 'custom-background', $custom_backgrounds_defaults  );
          
            add_theme_support( 'html5', array( 'search-form' ) );
            add_theme_support( 'custom-spacing');
            add_theme_support( 'appearance-tools' );
            add_theme_support( 'post-formats',  array( 'aside', 'gallery', 'quote', 'image', 'video' ) );
            add_theme_support('core-block-patterns');
            add_theme_support( 'editor-styles' );
            add_editor_style('style-editor.css');

            function theme_slug_setup() { add_theme_support( 'title-tag' ); } add_action( 'after_setup_theme', 'theme_slug_setup' );

                //block-library-styles abschalten, betrieb dann mit classic-editor
                function gutenberg_style_abschalten() {
                    wp_dequeue_style( 'wp-block-library' ); }
                    add_action( 'wp_enqueue_scripts', 'gutenberg_style_abschalten', 100 );

                    // Emojis entfernen

                    function remove_emoji()
                    {
                    remove_action('wp_head', 'print_emoji_detection_script', 7);
                    remove_action('admin_print_scripts', 'print_emoji_detection_script');
                    remove_action('admin_print_styles', 'print_emoji_styles');
                    remove_action('wp_print_styles', 'print_emoji_styles');
                    remove_filter('the_content_feed', 'wp_staticize_emoji');
                    remove_filter('comment_text_rss', 'wp_staticize_emoji');
                    remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
                    add_filter('tiny_mce_plugins', 'remove_tinymce_emoji');
                    }


                    add_action('init', 'remove_emoji');
                    function remove_tinymce_emoji($plugins)
                    {
                    if (!is_array($plugins))
                        {
                        return array();
                        }
                    return array_diff($plugins, array(
                        'wpemoji'
                    ));
                    }



                // fix custo,izer ???

                add_filter('the_tags', 'wp32234_add_span_get_the_tag_list');

function wp32234_add_span_get_the_tag_list($list) {
    $list = str_replace('rel="tag">', 'rel="tag"><span>', $list);
    $list = str_replace('</a>', '</span></a>', $list);
    return $list;
}

                //remove_action('shutdown', 'wp_ob_end_flush_all', 1);


                //Sidebar 
                function wpnoob_widgets_init() {
                    register_sidebar( array(
                        'name'          => __( 'Primary Sidebar', 'wpnoob' ),
                        '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'          => __( 'Secondary Sidebar', 'wpnoob' ),
                        'id'            => 'sidebar-1',
                        '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', 'my_register_sidebars' );
                function my_register_sidebars() {
                    /* Register the 'primary' sidebar. */
                    register_sidebar(
                        array(
                            'id'            => 'sidebar-1',
                            'name'          => __( 'Primary Sidebar', 'wpnoob' ),
                            'description'   => __( 'Just a Sidebar. You can put a Menu in here.', 'wpnoob' ),
                            'before_widget' => '<div id="%1$s" class="widget %2$s">',
                            'after_widget'  => '</div>',
                            'before_title'  => '<h3 class="widget-title">',
                            'after_title'   => '</h3>',
                        )
                    );
                }
                /* Repeat register_sidebar() code for additional sidebars. */

                //Registrieren von Customizer-Funktionalität

                    function wpnoob_post_title( $heading, $post ) {
                        echo '<' . $heading . ' class="entry-title">';
                        if ( ! is_single() ) { ?>
                        <a href="<?php esc_url( the_permalink() ); ?>">
                        <?php }
                        the_title();
                        if ( ! is_single() ) { ?>
                        </a>
                        <?php }
                        echo '</' . $heading . '>';
                        }
                
                        function wpnoob_the_content() {
                        $text = _x( 'Continue reading “%s”', 's = post title', 'wpnoob' );
                        $more = sprintf( $text, esc_html( get_the_title() ) );
                        the_content( $more );
                        }

                // JS defer-Attribut setzen

                    add_filter( 'script_loader_tag', 'add_defer_attribute', 10, 2 );
                    function add_defer_attribute( $tag, $handle ) {
                        $scripts_to_defer = array( 'my-header-js', 'my-helper-js' );
                        
                        foreach( $scripts_to_defer as $defer_script )
                            if( $defer_script === $handle )
                                return str_replace( ' src', ' defer="defer" src', $tag );
                        
                        return $tag;
                    }
                
                //JS einbinden

                function themeslug_enqueue_helper_script() {
                        wp_enqueue_script( 'my-helper-js', get_stylesheet_directory_uri().'/js/dom-helper.js', false );
                    }
                    add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_helper_script' );
                    /* function themeslug_enqueue_header_script() {
                        wp_enqueue_script( 'my-header-js', get_stylesheet_directory_uri().'/js/header.js', false );
                    } */
                    function themeslug_enqueue_header_script() {
                        wp_enqueue_script( 'my-header-js', get_stylesheet_directory_uri().'/js/header.js', array(), null, true );
                    }
                    add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_header_script' );
                





                    //Tags & Categories
                    function add_taxonomies_to_pages() {     register_taxonomy_for_object_type( 'post_tag', 'page' );    register_taxonomy_for_object_type( 'category', 'page' );}add_action( 'init', 'add_taxonomies_to_pages' );  if ( ! is_admin() ) {       add_action( 'pre_get_posts', 'category_and_tag_archives' ); }function category_and_tag_archives( $wp_query ) {  $my_post_array = array('post','page');  if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) ) $wp_query->set( 'post_type', $my_post_array );  if ( $wp_query->get( 'tag' ) )  $wp_query->set( 'post_type', $my_post_array );}







                //funktionen für comment.php, author-link in den comments führt sonst auf die startseite
                function use_author_link_as_comment_author_url( $url, $id, $comment ) {
                    if ( $comment->user_id ) {
                        return get_author_posts_url( $comment->user_id );
                    }
                    return $url;
                }
                add_filter( 'get_comment_author_url', 'use_author_link_as_comment_author_url', 10, 3 );

                // excerpt_more should be set the empty.
                    add_filter( 'excerpt_more', '__return_empty_string', 21 );

                    function wpse_134143_excerpt_more_link( $excerpt ) {
                        $excerpt .= sprintf( 
                                '<a href="%s" class="cp-archives-read-more-link">%s</a>',
                                esc_url( get_permalink() ),
                                __( '...read more &nbsp;&raquo;', 'wpnoob' )
                        );
                        return $excerpt;
                    }
                    add_filter( 'the_excerpt', 'wpse_134143_excerpt_more_link', 21 );

                
                //archives ## hooks for wp_get_archives();
                
                
                function featured_image_support() {
                    add_theme_support( 'post-thumbnails' );
                }
                add_action( 'after_setup_theme', 'featured_image_support' );
            
                
               


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    }
endif; // wpnoob_setup
add_action( 'after_setup_theme', 'wpnoob_setup' );

add_action('wp_enqueue_scripts', 'wpnoob_enqueue_styles');

function wpnoob_enqueue_styles() {
    wp_enqueue_style('preload-style', get_stylesheet_uri(), false, null);
    add_filter('style_loader_tag', 'wpnoob_preload_filter', 10, 2);
}

function wpnoob_preload_filter($html, $handle) {
    if ($handle === 'preload-style') {
        $html = str_replace("rel='stylesheet'", "rel='preload' as='style'", $html);
    }
    return $html;
}

本文标签: wp enqueue stylehow do I include wpenqueuestyle correctly