Skip to content

Latest commit

 

History

History
93 lines (72 loc) · 1.38 KB

File metadata and controls

93 lines (72 loc) · 1.38 KB
sidebar_position 1

Block Attribute Sources

Understanding how the VIP Block Data API extracts block attributes from HTML.

Attribute Source Types

The plugin supports all WordPress attribute sources:

1. attribute

Extracts HTML element attributes:

{
  "url": {
    "type": "string",
    "source": "attribute",
    "selector": "img",
    "attribute": "src"
  }
}

2. html

Extracts inner HTML content:

{
  "content": {
    "type": "string",
    "source": "html",
    "selector": "p"
  }
}

3. text

Extracts plain text content:

{
  "citation": {
    "type": "string",
    "source": "text",
    "selector": "cite"
  }
}

4. query

Extracts arrays of data:

{
  "images": {
    "type": "array",
    "source": "query",
    "selector": "img",
    "query": {
      "url": {
        "type": "string",
        "source": "attribute",
        "attribute": "src"
      },
      "alt": {
        "type": "string",
        "source": "attribute",
        "attribute": "alt"
      }
    }
  }
}

Server-Side Registration Required

For custom blocks, server-side registration with block.json is required:

register_block_type( __DIR__ . '/build/custom-block' );

Next Steps