Astra_Attr::astra_attr( string $context, array $attributes = array(), array $args = array() )

Build list of attributes into a string and apply contextual filter on string.


Description

The contextual filter is of the form astra_attr_{context}_output.


Parameters

$context

(string) (Required) The context, to build filter name.

$attributes

(array) (Optional) Extra attributes to merge with defaults.

Default value: array()

$args

(array) (Optional) Custom data to pass to filter.

Default value: array()


Return

(string) String of HTML attributes and values.


Source

File: inc/core/class-astra-attr.php

		public function astra_attr( $context, $attributes = array(), $args = array() ) {

			$attributes = $this->astra_parse_attr( $context, $attributes, $args );

			$output = '';

			// Cycle through attributes, build tag attribute string.
			foreach ( $attributes as $key => $value ) {

				if ( ! $value ) {
					continue;
				}

				if ( true === $value ) {
					$output .= esc_html( $key ) . ' ';
				} else {
					$output .= sprintf( '%s="%s" ', esc_html( $key ), esc_attr( $value ) );
				}
			}

			$output = apply_filters( "astra_attr_{$context}_output", $output, $attributes, $context, $args );

			return trim( $output );
		}

Changelog

Changelog
Version Description
1.6.2 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.