Great Ocean Media
website design - editorial & pr services - freelance journalism

adi_wrap – Automatic wrapper

This plugin will wrap its contents in an HTML tag – but only if there’s something to wrap.


Simply put the adi_wrap tag around the contents you need wrapped up:

<txp:adi_wrap wraptag="HTML tag">
	...contained statements...

and if the “…contained statements…” generate some output then they’ll be surrounded by the HTML tag of your choice.

Using adi_wrap will help avoid the creation of empty tags in your markup.

And if you need some extra HTML attributes, it’ll do that too. Have a look in the examples.



- the (X)HTML tag (without ‘<>’ brackets) to wrap around the link. Default = “div”.
If there is no content to output then no wraptag is generated.

class="class name"

- the CSS class to be used on the wraptag. Default = “” (none).

html_id="id name"

- the HTML ID to be used on the wraptag. Default = “” (none).


- some text to precede the wrapped content. Default = “” (no label).


- the (X)HTML tag (without ‘<>’ brackets) to wrap around the label. Default = “” (no tag).

label_class="class name"

- the class to be used on the label’s tag. Default = “menu_label”.

label_id="id name"

- the ID to be used on the label’s tag. Default = “” (none).


- some text to precede the content inside the wraptag. Default = “” (no prefix).


- some text to appended to the end of the content inside the wraptag. Default = “” (no suffix).


- an additional HTML attribute to add to the wraptag. Underscores are converted to hyphens. Default = “” (no extra HTML attribute).


- set to “1” to trim whitespace off the ends of your wrapped content. Default for wraptag = “0” (no trim). Default for prefix/suffix = “1” (trim).


Typically adi_wrap is of most use when you need something wrapped up in an HTML tag …

… but the contained code doesn’t have its own wraptag attribute, e.g.:

<txp:adi_wrap wraptag="em">
	<txp:custom_field name="might_be_blank" />

… or that the contained statements may not produce any output, e.g.:

<txp:adi_wrap wraptag="p">
	<txp:custom_field name="might_be_blank" />
	<txp:custom_field name="might_be_blank_too" />

… or you want to double wrap something:

	<txp:article wraptag="ul" break="li" keywords="uncommon">
		...contained statements...

Note that adi_wrap, in the above example, will use the default wraptag of “div”.

You can add additional HTML attributes to the wrap tag. For example role:

<txp:adi_wrap wraptag="nav" role="navigation">
		...contained statements...

will generate <nav role="navigation"> ... </nav>

<txp:adi_wrap wraptag="li" data_theme="classic">
		...contained statements...

will generate <li data-theme="classic"> ... </li>

Note that you need to specify the attribute using underscores in place of hyphens, these are converted automatically for the markup.

Additional information

Support and further information can be obtained from the Textpattern support forum. A copy of this help is also available online. More adi_plugins can be found here.

adi_wrapv0.2Download (Uncompressed) SupportTXP 4.5+