Skip to content
scribu edited this page Feb 24, 2012 · 6 revisions

html() is a function you can use for generating HTML.

Note that the attributes are passed through esc_attr(), but the content is not escaped in any way.

Basic

  • Input: html( 'p', 'Hello world!' );
  • Output: <p>Hello world!</p>

Attributes

  • Input: html( 'a', array( 'href' => 'http://example.com' ), 'A link' );
  • Output: <a href="http://example.com">A link</a>

Boolean Attributes

  • Input: html( 'input', array( 'type' => 'checkbox', 'name' => 'foo', 'checked' => true ) );

  • Output: <input type="checkbox" name="foo" checked="checked" />

  • Input: html( 'input', array( 'type' => 'checkbox', 'name' => 'foo', 'checked' => false ) );

  • Output: <input type="checkbox" name="foo" />

Multiple arguments as content

Input:

html( 'ul',
  html( 'li', 'foo' ),
  html( 'li', 'bar' )
);

Output: <ul><li>foo</li><li>bar</li></ul>

Clone this wiki locally