Skip to content

Shortcode and blocks

Since 1.0 you can show the value of a field on your website without writing code: with a shortcode, or by binding a block to the field.

Which fields can be shown

A value is only shown on the website when Use in shortcode and blocks is switched on for its field. New fields have it on; fields made before 1.0 have it off.

  • Only fields of Admin Options Pages can be shown. Options of WordPress or other plugins never are.
  • A password field is never shown.
  • When an option has no value yet, the Default value of its field is shown.

The editor shows the shortcode of a field, with a copy button, while the setting is on.

The shortcode

[aop_option name="company_name"]
Attribute For What it does
name all types The field name of the field. Required.
default all types Shown when the value is empty.
format date, time, date and time A PHP date format. Default: the date or time format of the site.
size image An image size such as thumbnail, medium or large. Default: full.
text email, link, file The text of the link. Makes an email address or URL a link.
link email, link, file 1 makes an email address or URL a link. 0 shows only the URL of a file.

Examples

Call us: [aop_option name="phone" default="Not available"]

[aop_option name="contact_email" link="1"]

[aop_option name="price_list" text="Download our price list"]

Next event: [aop_option name="event_date" format="l j F Y"]

[aop_option name="company_logo" size="medium"]

What each type shows

  • Text field, textarea, number, range: the value. Numbers use the number format of the site.
  • Wysiwyg editor: the HTML, with paragraphs. Shortcodes inside it are not run.
  • Email: the address, hidden from simple spam bots.
  • Image: the image. File: a link to the file.
  • Checkbox: the Text when checked or Text when not checked of the field, or 1/0 when that text is empty.
  • Select, radio buttons, button group: the stored value.
  • Date and time: in the format of the site, or of format.

A field that cannot be shown shows nothing. Logged in as an administrator, you see the reason in an HTML comment in the source of the page.

Block Bindings

With Block Bindings a block takes its content from a field. Change the value on your options page, and every bound block shows the new value.

  1. Select a block in the block editor or the site editor, for example a paragraph.
  2. Open the Attributes panel in the block settings (WordPress 6.9 and later).
  3. Choose the attribute, such as Content, and then a field of Admin Options Pages.

The block now shows the value of the field, in the editor and on the website. You change the value on the options page, not in the block.

Supported blocks

Block Attributes
Paragraph, Heading, List item content
Button text, url, link target, rel
Image id, url, title, alt, caption
Post date date
Navigation link url

In code

The binding source is aop/option, with the field name in args.name:

<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"aop/option","args":{"name":"phone"}}}}} -->
<p>Shown when the field cannot be shown</p>
<!-- /wp:paragraph -->