-
Notifications
You must be signed in to change notification settings - Fork 62
7. FAQ
Q. How do I access the "Additional CSS Class" setting in my template?
A. This setting is saved using a pre-defined slug: className.
You can output it using block_field('className') or echo block_value('className').
Q. The block_value() template function only returns an ID for my Image field. How do I get the URL?
A. To get the image URL, you can use the wp_get_attachment_image() function, like this:
$image_id = block_value( 'image' ); // This will return the image's ID.
$image_url = wp_get_attachment_image( $image_id, 'thumbnail' );Using wp_get_attachment_image is a really handy way of getting the best image size for the job. You can even pass an array of width and height to get the most optimal image:
$image_url = wp_get_attachment_image( $image_id, array( 800, 600) );Q. What prefix does Block Lab use for custom blocks? WordPress uses core for the blocks that come standard with WordPress (e.g. core/paragraph, core/image), so what does Block Lab use?
A. Custom blocks built with Block Lab are prefixed with block-lab. For example, if you created a custom block with the name feature, it would be registered as block-lab/feature.