PDF Embedder Documentation

Documentation, Reference Materials, and Tutorials for PDF Embedder

How to include attachment pages in search results

To include the attachment page of your embedded PDFs in the search results, add a small PHP snippet to your theme’s functions.php file (if using a child theme or theme that has option to add custom functions without altering the original theme code), or add the snippet to a custom code plugin such as My Custom Functions or Functionality.

The code to add is as follows and will instruct your site to include attachment page URLs to the search results:

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

add_filter( 'pre_get_posts', 'attachment_search' );Code language: PHP (php)

Still have questions? We’re here to help!

Last Modified: