add_class example

$position_styles,
            array(
                'context'  => 'block-supports',
                'prettify' => false,
            )
        );

        // Inject class name to block container markup.         $content = new WP_HTML_Tag_Processor( $block_content );
        $content->next_tag();
        foreach ( $wrapper_classes as $class ) {
            $content->add_class( $class );
        }
        return (string) $content;
    }

    return $block_content;
}

// Register the block support. WP_Block_Supports::get_instance()->register(
    'position',
    array(
        

    if ( null === $link_color && null === $hover_link_color ) {
        return $block_content;
    }

    // Like the layout hook this assumes the hook only applies to blocks with a single wrapper.     // Add the class name to the first element, presuming it's the wrapper, if it exists.     $tags = new WP_HTML_Tag_Processor( $block_content );
    if ( $tags->next_tag() ) {
        $tags->add_class( wp_get_elements_class_name( $block ) );
    }

    return $tags->get_updated_html();
}

/** * Renders the elements stylesheet. * * In the case of nested blocks we want the parent element styles to be rendered before their descendants. * This solves the issue of an element (e.g.: link color) being styled in both the parent and a descendant: * we want the descendant style to take priority, and this is done by loading it after, in DOM order. * * @since 6.0.0 * @since 6.1.0 Implemented the style engine to generate CSS and classnames. * @access private * * @param string|null $pre_render The pre-rendered content. Default null. * @param array $block The block being rendered. * @return null */
$slug         = $global_styles_block_names[ $block['blockName'] ]; // e.g. 'blue-orange'.             $filter_id    = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-blue-orange'.             $filter_value = self::get_css_var( $slug ); // e.g. 'var(--wp--preset--duotone--blue-orange)'.
            // CSS custom property, SVG filter, and block CSS.             self::enqueue_global_styles_preset( $filter_id$duotone_selector$filter_value );
        }

        // Like the layout hook, this assumes the hook only applies to blocks with a single wrapper.         $tags = new WP_HTML_Tag_Processor( $block_content );
        if ( $tags->next_tag() ) {
            $tags->add_class( $filter_id );
        }
        return $tags->get_updated_html();
    }

    /** * Appends the used block duotone filter declarations to the inline block supports CSS. * * Uses the declarations saved in earlier calls to self::enqueue_block_css. * * @since 6.3.0 */
    
$color_classes       = get_color_classes_for_block_core_search( $attributes );
    $typography_classes  = get_typography_classes_for_block_core_search( $attributes );
    $is_button_inside    = ! empty( $attributes['buttonPosition'] ) &&
        'button-inside' === $attributes['buttonPosition'];
    // Border color classes need to be applied to the elements that have a border color.     $border_color_classes = get_border_color_classes_for_block_core_search( $attributes );

    $label_inner_html = empty( $attributes['label'] ) ? __( 'Search' ) : wp_kses_post( $attributes['label'] );
    $label            = new WP_HTML_Tag_Processor( sprintf( '<label %1$s>%2$s</label>', $inline_styles['label']$label_inner_html ) );
    if ( $label->next_tag() ) {
        $label->set_attribute( 'for', $input_id );
        $label->add_class( 'wp-block-search__label' );
        if ( $show_label && ! empty( $attributes['label'] ) ) {
            if ( ! empty( $typography_classes ) ) {
                $label->add_class( $typography_classes );
            }
        } else {
            $label->add_class( 'screen-reader-text' );
        }
    }

    $input         = new WP_HTML_Tag_Processor( sprintf( '<input type="search" name="s" required %s/>', $inline_styles['input'] ) );
    $input_classes = array( 'wp-block-search__input' );
    

function block_core_heading_render( $attributes$content ) {
    if ( ! $content ) {
        return $content;
    }

    $p = new WP_HTML_Tag_Processor( $content );

    $header_tags = array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' );
    while ( $p->next_tag() ) {
        if ( in_array( $p->get_tag()$header_tags, true ) ) {
            $p->add_class( 'wp-block-heading' );
            break;
        }
    }

    return $p->get_updated_html();
}

/** * Registers the `core/heading` block on server. */
function register_block_core_heading() {
    
$style_attribute = $colors_supports['style'];
        }

        $inner_blocks_html = '';
        foreach ( $block->inner_blocks as $inner_block ) {
            $inner_blocks_html .= $inner_block->render();
        }

        if ( strpos( $inner_blocks_html, 'current-menu-item' ) ) {
            $tag_processor = new WP_HTML_Tag_Processor( $html );
            while ( $tag_processor->next_tag( array( 'class_name' => 'wp-block-navigation-item__content' ) ) ) {
                $tag_processor->add_class( 'current-menu-ancestor' );
            }
            $html = $tag_processor->get_updated_html();
        }

        $wrapper_attributes = get_block_wrapper_attributes(
            array(
                'class' => $css_classes,
                'style' => $style_attribute,
            )
        );

        
// return early if no settings are found on the block attributes.     $block_settings = _wp_array_get( $block, array( 'attrs', 'settings' ), null );
    if ( empty( $block_settings ) ) {
        return $block_content;
    }

    // Like the layout hook this assumes the hook only applies to blocks with a single wrapper.     // Add the class name to the first element, presuming it's the wrapper, if it exists.     $tags = new WP_HTML_Tag_Processor( $block_content );
    if ( $tags->next_tag() ) {
        $tags->add_class( _wp_get_presets_class_name( $block ) );
    }

    return $tags->get_updated_html();
}

/** * Render the block level presets stylesheet. * * @internal * * @since 6.2.0 * @since 6.3.0 Updated preset styles to use Selectors API. * @access private * * @param string|null $pre_render The pre-rendered content. Default null. * @param array $block The block being rendered. * * @return null */
// Get spacing CSS variable from preset value if provided.         if ( is_string( $gap ) && str_contains( $gap, 'var:preset|spacing|' ) ) {
            $index_to_splice = strrpos( $gap, '|' ) + 1;
            $slug            = _wp_to_kebab_case( substr( $gap$index_to_splice ) );
            $gap             = "var(--wp--preset--spacing--$slug)";
        }
    }

    $unique_gallery_classname = wp_unique_id( 'wp-block-gallery-' );
    $processed_content        = new WP_HTML_Tag_Processor( $content );
    $processed_content->next_tag();
    $processed_content->add_class( $unique_gallery_classname );

    // --gallery-block--gutter-size is deprecated. --wp--style--gallery-gap-default should be used by themes that want to set a default     // gap on the gallery.     $fallback_gap = 'var( --wp--style--gallery-gap-default, var( --gallery-block--gutter-size, var( --wp--style--block-gap, 0.5em ) ) )';
    $gap_value    = $gap ? $gap : $fallback_gap;
    $gap_column   = $gap_value;

    if ( is_array( $gap_value ) ) {
        $gap_row    = isset( $gap_value['top'] ) ? $gap_value['top'] : $fallback_gap;
        $gap_column = isset( $gap_value['left'] ) ? $gap_value['left'] : $fallback_gap;
        $gap_value  = $gap_row === $gap_column ? $gap_row : $gap_row . ' ' . $gap_column;
    }
'prettify' => false,
            )
        );

        $outer_class_names[] = $container_content_class;
    }

    // Return early if only child layout exists.     if ( ! $support_layout && ! empty( $outer_class_names ) ) {
        $content = new WP_HTML_Tag_Processor( $block_content );
        $content->next_tag();
        $content->add_class( implode( ' ', $outer_class_names ) );
        return (string) $content;
    }

    $global_settings = wp_get_global_settings();
    $fallback_layout = ! empty( _wp_array_get( $block_type->supports, array( 'layout', 'default' ), array() ) ) ? _wp_array_get( $block_type->supports, array( 'layout', 'default' ), array() ) : _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );
    $used_layout     = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $fallback_layout;

    $class_names        = array();
    $layout_definitions = wp_get_layout_definitions();
    $container_class    = wp_unique_id( 'wp-container-' );
    $layout_classname   = '';

    
Home | Imprint | This part of the site doesn't use cookies.