Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1.48 KB

readme.md

File metadata and controls

42 lines (33 loc) · 1.48 KB

WP Attributes

Latest Stable Version Total Downloads Latest Unstable Version License PHP from Packagist

An helper library to generate attributes for HTML elements.

Installation

composer require pressmodo/wp-attributes

Basic usage

use Pressmodo\Attributes\AttributesInterface;

$sut = new AttributesInterface();

$sut->add( 'context', [
    'class'	=> 'color-primary',
    'id'	=> 'unique_id',
] );

// ' class="color-primary" id="unique_id"'
echo $sut->render( 'context' );


$sut->add( 'another_context', [
    'class'	=> '', // This will be skipped because empty
    'attr1'	=> null, // This will be skipped because null
    'attr2'	=> false, // This will be skipped because false
    'attr3'	=> 0, // This will be skipped because 0 is also false
    'id'	=> 'unique_id',
] );
// ' id="unique_id"'
echo $sut->render( 'another_context' );

Credits