Mastering Wix Blog API: Setting Featured Image Alt Text Programmatically

Understanding the Wix Blog API and Featured Image Alt Text

The Wix Blog API provides developers with powerful tools to manage blog posts programmatically using Velo. A common use case is automating the creation and publishing of posts, which can significantly improve content management efficiency. However, a challenge arises when attempting to set the alt text for the featured image (post cover) through the draftPosts.updateDraftPost function. This article analyzes a recent Wix Studio community forum discussion and provides insights and potential solutions for this issue.

The Problem: Setting Alt Text for Featured Images via API

As highlighted in the Wix Studio community forum topic, developers are encountering difficulties in setting the alt text for featured images when creating blog posts using Velo and the wix-blog-backend API. While setting the featured image itself is achievable using the Wix URI format, the updateDraftPost function doesn't seem to directly support updating the alt text for this specific image.

The original poster noted that setting the featured image works when using the following Wix URI format:

wix:image://v1/ mediaId ~mv2.png/ filename #originWidth=700 originHeight=500

Example:

wix:image://v1/f1e6fe_...~mv2.png/Thumbnail.png#originWidth=700 originHeight=500

The core issue revolves around the lack of a documented method or property within the updateDraftPost function to directly manipulate the alt text associated with the featured image. This is crucial for SEO and accessibility, as alt text provides context for search engines and screen readers.

Potential Solutions and Workarounds

While a direct solution via updateDraftPost may not be immediately available, here are some potential approaches and workarounds to consider:

  1. Investigate the heroImage Property: Although the original poster clarified they were not referring to heroImage, it's worth re-examining this property to see if it indirectly influences the featured image or provides a hook for setting alt text. The documentation may not explicitly state this, but experimentation could reveal unexpected behavior.
  2. Utilize Wix Media Manager API: Explore the Wix Media Manager API to directly update the image metadata, including the alt text. The process would involve:
    • Uploading the image to the Wix Media Manager.
    • Retrieving the media ID.
    • Using the Media Manager API to update the image's alt text using the media ID.
    • Referencing the image in the blog post using the Wix URI format.

    This approach separates the image management from the blog post creation, offering more granular control over image metadata.

  3. Post-Publishing Update: If setting the alt text during draft creation is not possible, consider a post-publishing update using the wix-blog-backend API. This would involve:
    • Publishing the blog post without alt text.
    • Retrieving the published post ID.
    • Using the API to update the published post and set the featured image alt text.

    While this introduces an extra step, it ensures the alt text is set correctly.

  4. Leverage Wix Data Hooks: Implement a data hook that triggers after a blog post is saved or published. This hook can then use the Wix Media Manager API to update the alt text of the featured image. This approach provides a more automated solution, ensuring that alt text is consistently set for all blog posts.

Considerations for Wix Store Owners and Developers

For Wix store owners and developers relying on automated blog post creation, the inability to programmatically set featured image alt text presents a significant SEO and accessibility challenge. Implementing one of the workarounds described above is crucial to ensure that blog posts are optimized for search engines and accessible to all users. It's also important to monitor the Wix Developers documentation for updates to the Blog API that may address this issue directly in the future.

Furthermore, consider contributing to the Wix Studio community forum by sharing your findings and solutions. Collaboration within the community can lead to more effective workarounds and potentially influence future API enhancements.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools