admin管理员组

文章数量:1122826

I added the aspectRatio prop to the block.json file in a custom block that renders a grid of posts of a specific type:

{
    "$schema": ".json",
    "apiVersion": 3,
    "name": "my/custom-post-grid",
    "title": "Custom Post Grid",
    "description": "Display a grid of custom posts.",
    "textdomain": "mydomain",
    "category": "media",
    "attributes": {
        "category": {
            "type": "integer",
            "default": 0
        },
        "columns": {
            "type": "integer",
            "default": 3
        },
        "gap": {
            "type": "string",
            "default": "10px"
        }
    },
    "supports": {
        "dimensions": {
            "aspectRatio": true
        },
        "spacing": {
            "margin": true,
            "padding": true
        },
        "typography": {
            "fontSize": true,
            "__experimentalFontFamily": true
        }
    },
    "editorScript": "file:./index.js",
    "style": "file:./style-index.css"
}

But, I can't see the aspect ratio selector in the block sidebar:

What am I doing wrong?

I added the aspectRatio prop to the block.json file in a custom block that renders a grid of posts of a specific type:

{
    "$schema": "https://schemas.wp.org/trunk/block.json",
    "apiVersion": 3,
    "name": "my/custom-post-grid",
    "title": "Custom Post Grid",
    "description": "Display a grid of custom posts.",
    "textdomain": "mydomain",
    "category": "media",
    "attributes": {
        "category": {
            "type": "integer",
            "default": 0
        },
        "columns": {
            "type": "integer",
            "default": 3
        },
        "gap": {
            "type": "string",
            "default": "10px"
        }
    },
    "supports": {
        "dimensions": {
            "aspectRatio": true
        },
        "spacing": {
            "margin": true,
            "padding": true
        },
        "typography": {
            "fontSize": true,
            "__experimentalFontFamily": true
        }
    },
    "editorScript": "file:./index.js",
    "style": "file:./style-index.css"
}

But, I can't see the aspect ratio selector in the block sidebar:

What am I doing wrong?

Share Improve this question asked Jul 12, 2024 at 7:36 leemonleemon 2,0024 gold badges22 silver badges51 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2 +50

Per the developer handbook:

This value signals that a block supports some of the CSS style properties related to dimensions. When it does, the block editor will show UI controls for the user to set their values if the theme declares support.

So in your theme you'll need to declare support either by setting appearanceTools to true in theme.json or the legacy way using add_theme_support( 'appearance-tools' ) in functions.php.

本文标签: No aspect ratio selector in a custom block