• I’m using WP 6.01 and 20-22 theme and I’m a WP novice. I’m using a large quantity of image blocks to display recipe information.

    How do I make the blocks searchable? I’ve tried Alt Text and Title Attribute, but neither appear to be searchable.

    Would appreciate suggestions.

Viewing 4 replies - 1 through 4 (of 4 total)
  • @boz2006

    Where you want to search image block ? If it is default wordpress search you need to add related page title and description ? If you share more details regarding search i can check for you.

    Thread Starter Boz2006

    (@boz2006)

    Currently I use the default WP search field (extreme top right of my theme). I wanted to have multiple blocks on each page, but each one to be individually searchable. Keywords would be very simple – Beetroot, carrot, coriander….

    Maybe there’s a search plugin for more advanced search?

    This particular site is purely for private use, and access is blocked by using My. Private Site.

    • This reply was modified 3 years, 8 months ago by Boz2006. Reason: additional info
    • This reply was modified 3 years, 8 months ago by Boz2006.

    @boz2006

    Try adding below code in your theme functions.php file to modify default wordpress search with attachment. Your image name must match search keyword to work.

    function attachment_search( $query ) {
        if ( $query->is_search ) {
           $query->set( 'post_type', array( 'post','page', 'attachment' ) );
           $query->set( 'post_status', array( 'publish', 'inherit' ) );
        }
    
       return $query;
    }
    add_filter( 'pre_get_posts', 'attachment_search' );

    I hope this will help you!

    Thread Starter Boz2006

    (@boz2006)

    Many thanks – much appreciated.

    One question: What and where is the image name? Surely, if the image had a name, then the default WP search would be OK?

    • This reply was modified 3 years, 8 months ago by Boz2006.
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Making image blocks searchable’ is closed to new replies.