How do I include featured images in my WordPress based engine?


The posts and pages in my WordPress site have featured images set, but those image links don’t appear to be included in my results indexed with the Swiftype WordPress plug-in. How do I fix this?

To include featured image links with your WordPress search engine results, you’ll need to add a custom function to your theme’s functions.php file.

Here’s an example function that will use the featured image of the post as the image field value in Swiftype:

function update_swiftype_document_url($document, $post) {
    $image = wp_get_attachment_image_src(get_post_thumbnail_id($post - > ID), 'thumbnail');
    $document['fields'][] = array('name' => 'image',
        'type' => 'enum',
        'value' => $image[0]);

    return $document;

add_filter('swiftype_document_builder', 'update_swiftype_document_url', 10, 2);

This function should work in most cases, but might need to be modified depending on how you’ve customized your WordPress theme.

You can find additional information in our Customizing Wordpress Tutorials documentation.

How do I include images in the Swiftype WordPress plug-in's autocomplete dropdown?