bricks_upload_media
Overview
Upload an image to the WordPress media library from a remote URL. The tool downloads the image from the specified URL, stores it in the WordPress uploads directory, and returns the media ID and URL for immediate use in Bricks elements.
This is the essential first step before referencing images in sections, hero backgrounds, cards, or any visual element. The returned media ID can be used in image elements, featured images, or background settings.
Key Features
When to Use
Uploading hero backgrounds, card images, or logo files from external URLs
Preparing media assets during the design system setup phase
Importing images from a design prototype or stock photo service
Setting up featured images for posts created with bricks_create_post
WordPress media upload permissions enabled
Sufficient server disk space for the uploaded file
When NOT to Use
You need to upload non-image files like videos or PDFs (limited MIME type support)
The source URL requires authentication or is behind a firewall
Parameters
urlstringREQUIREDfilenamestringREQUIREDalt_textstringoptionalCode Examples
Warning: Undefined array key "example_output" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 12
Upload a hero background image
Download an image from Unsplash and store it in the media library with descriptive alt text.
bricks_upload_media({
url: "https://images.unsplash.com/photo-example.jpg",
filename: "hero-background.jpg",
alt_text: "Modern office workspace with laptops and plants"
})
// Returns: { id: 42, url: "https://site.com/wp-content/uploads/2025/01/hero-background.jpg", width: 1920, height: 1080, alt_text: "Modern office workspace..." }Warning: Undefined array key "example_output" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 12
Upload and use in a Bricks image element
Upload an image then reference it by ID in a Bricks section element.
// Step 1: Upload the image
const media = await bricks_upload_media({
url: "https://example.com/team-photo.jpg",
filename: "team-member-john.jpg",
alt_text: "John Smith, Lead Developer"
});
// Step 2: Use in a Bricks image element
{ "type": "image", "settings": {
"image": { "id": media.id, "url": media.url },
"_width": "100%",
"_aspectRatio": "16/9"
}}Common Mistakes
Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018
Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48
Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018
Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48
Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
Tips & Warnings
Always upload images before building sections that reference them. The returned media ID is needed for image elements and featured images.
Use descriptive filenames like « hero-background.jpg » or « team-member-john.jpg » instead of generic names. This helps with media library organization and SEO.
Check the media library first with bricks_list_media to avoid uploading duplicates.