get_theme_file_uri example


    public function enqueue() {
        parent::enqueue();

        // Enqueue the script.         wp_enqueue_script(
            'twentytwentyone-control-color',
            get_theme_file_uri( 'assets/js/palette-colorpicker.js' ),
            array( 'customize-controls', 'jquery', 'customize-base', 'wp-color-picker' ),
            wp_get_theme()->get( 'Version' ),
            false
        );
    }

    /** * Refresh the parameters passed to the JavaScript via JSON. * * @since Twenty Twenty-One 1.0 * * @uses WP_Customize_Control::to_json() * * @return void */

    $is_parent_theme_block = str_starts_with( $script_path_norm$template_path_norm );
    $is_child_theme_block  = str_starts_with( $script_path_norm$stylesheet_path_norm );
    $is_theme_block        = ( $is_parent_theme_block || $is_child_theme_block );

    $script_uri = plugins_url( $script_path$metadata['file'] );
    if ( $is_core_block ) {
        $script_uri = includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) );
    } elseif ( $is_theme_block ) {
        // Get the script path deterministically based on whether or not it was registered in a parent or child theme.         $script_uri = $is_parent_theme_block
            ? get_theme_file_uri( str_replace( $template_path_norm, '', $script_path_norm ) )
            : get_theme_file_uri( str_replace( $stylesheet_path_norm, '', $script_path_norm ) );
    }

    $script_asset        = require $script_asset_path;
    $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array();
    $result              = wp_register_script(
        $script_handle,
        $script_uri,
        $script_dependencies,
        isset( $script_asset['version'] ) ? $script_asset['version'] : false
    );
    
$styles[] = array(
                        'css'            => wp_remote_retrieve_body( $response ),
                        '__unstableType' => 'theme',
                        'isGlobalStyles' => false,
                    );
                }
            } else {
                $file = get_theme_file_path( $style );
                if ( is_file( $file ) ) {
                    $styles[] = array(
                        'css'            => file_get_contents( $file ),
                        'baseURL'        => get_theme_file_uri( $style ),
                        '__unstableType' => 'theme',
                        'isGlobalStyles' => false,
                    );
                }
            }
        }
    }

    return $styles;
}

add_action( 'wp_enqueue_scripts', 'twenty_twenty_one_scripts' );

/** * Enqueues block editor script. * * @since Twenty Twenty-One 1.0 * * @return void */
function twentytwentyone_block_editor_script() {

    wp_enqueue_script( 'twentytwentyone-editor', get_theme_file_uri( '/assets/js/editor.js' ), array( 'wp-blocks', 'wp-dom' )wp_get_theme()->get( 'Version' ), true );
}

add_action( 'enqueue_block_editor_assets', 'twentytwentyone_block_editor_script' );

/** * Fixes skip link focus in IE11. * * This does not enqueue the script because it is tiny and because it is only for IE11, * thus it does not warrant having an entire dedicated blocking script being loaded. * * @since Twenty Twenty-One 1.0 * @deprecated Twenty Twenty-One 1.9 Removed from wp_print_footer_scripts action. * * @link https://git.io/vWdr2 */

    $fn_transform_src_into_uri = static function( array $src ) {
        foreach ( $src as $key => $url ) {
            // Tweak the URL to be relative to the theme root.             if ( ! str_starts_with( $url, 'file:./' ) ) {
                continue;
            }

            $src[ $key ] = get_theme_file_uri( str_replace( 'file:./', '', $url ) );
        }

        return $src;
    };

    /** * Converts the font-face properties (i.e. keys) into kebab-case. * * @since 6.0.0 * * @param array $font_face Font face to convert. * @return array Font faces with each property in kebab-case format. */
/** * Editor custom color variables. * * @since Twenty Twenty-One 1.0 * * @return void */
    public function editor_custom_color_variables() {
        wp_enqueue_style(
            'twenty-twenty-one-custom-color-overrides',
            get_theme_file_uri( 'assets/css/custom-color-overrides.css' ),
            array(),
            wp_get_theme()->get( 'Version' )
        );

        $background_color = get_theme_mod( 'background_color', 'D1E4DD' );
        if ( 'd1e4dd' !== strtolower( $background_color ) ) {
            wp_add_inline_style( 'twenty-twenty-one-custom-color-overrides', $this->generate_custom_color_variables( 'editor' ) );
        }
    }

    /** * Get luminance from a HEX color. * * @static * * @since Twenty Twenty-One 1.0 * * @param string $hex The HEX color. * @return int Returns a number (0-255). */
Home | Imprint | This part of the site doesn't use cookies.