The Attributes tab turns a snippet into something editors can configure. Each attribute becomes a field in the WP Coder block and a shortcode attribute, and its value is inserted into your HTML and PHP (and in Pro into inline CSS and JS).
The free WP Coder has 8 field types; WP Coder Pro adds 12 more, labels and help text — they are marked PRO below.
Adding an attribute#
Click Add attribute. Each row has:
| Setting | Purpose |
|---|---|
| Attribute name | The variable name used in code and as the shortcode attribute (button_text). |
| Default value | The value a new block starts with. For Select, Range and Repeater this field holds their setup instead — options, slider limits, sub-fields — edited in a dialog behind the { } button (in the free plugin, type a Range as min:max:step:default). |
| Field type | How the value is edited and processed — see the table below. |
| Label PRO | Optional. The field name editors see in the block. Empty uses the attribute name (show_badge → “Show Badge”). |
| Help text PRO | Optional. A hint shown as an ⓘ tooltip next to the field in the block. |
Remove attribute removes a row with Undo. In WP Coder Pro you can also reorder rows by dragging the handle (or focus it and use the arrow keys), and a problem with a name — empty, a duplicate, a reserved word — is written under the field. PRO
Naming rules#
Use lowercase letters and underscores (button_text). Don’t use id or title — the shortcode uses them — and avoid dashes and camelCase.
Using values in code#
For an attribute named heading:
| Where | Syntax | Notes |
|---|---|---|
| HTML | {{$heading}} |
Replaced with the value. |
| CSS PRO | {{$heading}} |
Only with Inline on. |
| JS PRO | {{$heading}} |
Only with Inline on; inserted JavaScript-safe (strings quoted). |
| PHP | $heading |
A variable. |
| Loop Logic PRO | <If field="heading" …> |
See Loop Logic. |
Values come from the block fields or from the shortcode:
[wp_code id="12" heading="Our team" show_badge="1"]
An attribute that is not passed in a shortcode is empty — the Default value is only the starting value of a new block and of the ready-made shortcode (Copy with attributes in the sidebar). Pass every value your code needs, or start from that shortcode.
Field types#
| Type | Stores | Notes |
|---|---|---|
| Text (single line) | One line, inline HTML allowed (<strong>, <em>, <a>, <span>, <br>) |
Block tags and unsafe markup are removed. |
| Textarea (multi-line) | Several lines, simple HTML | Line breaks become <br>. |
| Rich text PRO | Formatted HTML from a visual editor | Safe HTML is kept. |
| Number | A number | Inserted unquoted in inline JS. |
| Range / slider | A number | Limits in the Edit Range Limits dialog: min, max, step, default — stored as min:max:step:default, e.g. 0:1200:10:600. Fractional steps work (0:1:0.1). |
| Toggle (on/off) PRO | 1 or empty |
Test with <If field="name" value="1"> or if ( $name ). Default 1 starts the block switched on. |
| Select / dropdown PRO | The chosen value | Options in the Edit Select Options dialog, one per line as value:Label. A new block starts on the first option. |
| Image | An image | Expanded into image sub-variables. |
| Image (with preload) PRO | An image | The same, plus a <link rel="preload"> in the head — for a hero image. |
| SVG file (media library) PRO | An SVG file | {{$logo}} is a reference into a sprite embedded once at the end of the page; {{$logo_inline}} gives full markup. See SVG Icons in Blocks. |
| Icon (Icons page) PRO | An icon name | A reference into the shared icons.svg. See Icons. |
| Font Awesome icon PRO | An icon class | Use as <i class="{{$icon}}"></i>. |
| URL / link | A URL | javascript: links are removed. |
| Post / page (pick one) PRO | A post ID | See Post and Term fields. |
| Taxonomy term (pick one) PRO | A term ID | See Post and Term fields. |
| Colour picker (simple) | A colour | |
| Colour picker (advanced) PRO | A colour | A full colour picker with hue, saturation and value controls. |
| Gradient PRO | A CSS gradient | |
| Date / time | A date and time | |
| Repeater (list of items) PRO | Several rows | See Repeater. |
WP Coder (free): a Text value typed into a block (or into a shortcode by an author who may not post raw HTML) is printed as plain text, and a Textarea keeps its line breaks but no HTML.
Image sub-variables#
For an image attribute named hero:
| Placeholder | Output |
|---|---|
{{$hero}} / {{$hero_url}} |
Image URL |
{{$hero_alt}} |
Alt text |
{{$hero_width}} / {{$hero_height}} |
Size in pixels |
{{$hero_srcset}} / {{$hero_sizes}} |
srcset / sizes |
{{$hero_loading}}, {{$hero_fetchpriority}}, {{$hero_decoding}} |
Loading attributes chosen by WordPress |
{{$hero_html}} |
A full <img> tag with WordPress’s loading optimisation |
{{$hero_html_high}} |
<img> with fetchpriority="high" — for a hero outside the main content |
Use {{$hero_html}} for normal images. An empty image prints nothing. The same sub-variables work inside a Pro repeater ({{loop.photo_html}}).
Post and Term fields PRO#
Post / page (pick one) lets editors search and pick a published post, page or custom post type entry; Taxonomy term (pick one) does the same for a category, tag or custom taxonomy term. The { } button chooses which post types or taxonomies are offered — none ticked means all public ones.
The attribute holds the ID. Put it in a QuickCode placeholder (QuickCode must be on):
<h3><a href="{{post.link.id.{{$provider}}}}">{{post.title.id.{{$provider}}}}</a></h3>
{{not_empty.{{acf.price_from.id.{{$provider}}}}}}<p>From {{acf.price_from.id.{{$provider}}}}</p>{{/not_empty}}
<p>{{term.name.id.{{$topic}}}}</p>
Only published, non-password-protected items of the allowed types are shown. In PHP the attribute is the ID: get_field( 'price_from', $provider ).
Repeater PRO#
A repeater stores a list of rows — team members, pricing features, FAQ items. Its Default value holds the sub-fields, edited in the Edit Repeater Fields dialog.
Format: name:type,name2:type2. Sub-field types: text, textarea, richtext, number, url, image, color, gradient, range, date, icon, select, toggle, svg, library_icon.
- Range limits:
speed:range:0:200:5 - Select options:
size:select:s=Small|m=Medium|l=Large(or values only:status:select:active|draft) - Icon options:
icon:library_icon:color,logo:svg:color
name:text,role:text,photo:image,link:url,featured:toggle
In HTML (with Loop Logic on):
<ul class="team">
<Loop field="team">
<li>{{loop.photo_html}} <strong>{{loop.name}}</strong> {{loop.role}}</li>
</Loop>
</ul>
In PHP:
foreach ( wpcoder_get_repeater( $team ) as $row ) {
echo esc_html( $row['name'] );
}
Repeater fields keep HTML only in richtext sub-fields.
Safety of values#
Values typed into a block are escaped for the place they go: a URL field drops javascript: links, text can’t break out of an HTML attribute, and repeater fields keep markup only in Rich text sub-fields. The same applies to a shortcode written by a user who may not post raw HTML (for example a Contributor). Shortcodes written by administrators work as before.
Any character works in a block value, including [ and ] (Price [USD]). In a classic shortcode ] still ends the shortcode — that’s how WordPress reads shortcodes.