Automatically convert permalinks to PDFs in search results to the PDF itself, not the Attachment page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Automatically convert permalinks to PDFs in search results to the PDF itself, not the Attachment page | |
function my_force_direct_pdf_links( $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 esc_url( $permalink ); | |
} | |
add_filter( 'the_permalink', 'my_force_direct_pdf_links' ); | |
add_filter( 'attachment_link', 'my_force_direct_pdf_links' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@2ndkauboy: Thank you! Sorry for the delay on this, I guess you don't get notified about comments on Gists.