Skip to content

Instantly share code, notes, and snippets.

@2ndkauboy
Forked from jchristopher/functions.php
Last active May 30, 2016 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2ndkauboy/7cf99e621bfddddd8d237d27f955fbd5 to your computer and use it in GitHub Desktop.
Save 2ndkauboy/7cf99e621bfddddd8d237d27f955fbd5 to your computer and use it in GitHub Desktop.
Automatically convert permalinks to PDFs in search results to the PDF itself, not the Attachment page
<?php
// Automatically convert permalinks to PDFs in search results to the PDF itself, not the Attachment page
add_filter( 'the_permalink', function( $permalink ) {
global $post;
if ( is_search() && 'application/pdf' == get_post_mime_type( $post->ID ) ) {
// if the result is a PDF, link directly to the file not the attachment page
$permalink = wp_get_attachment_url( $post->ID );
}
return $permalink;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment