<?php | |
// Link directly to Media files instead of Attachment pages in search results | |
function my_search_media_direct_link( $permalink, $post = null ) { | |
if ( ( is_search() || doing_action( 'wp_ajax_searchwp_live_search' ) | |
|| doing_action( 'wp_ajax_nopriv_searchwp_live_search' ) ) | |
&& 'attachment' === get_post_type( $post ) ) { | |
$permalink = wp_get_attachment_url( $post ); | |
} | |
return esc_url( $permalink ); | |
} | |
add_filter( 'the_permalink', 'my_search_media_direct_link', 99, 2 ); | |
add_filter( 'attachment_link', 'my_search_media_direct_link', 99, 2 ); |
This comment has been minimized.
This comment has been minimized.
I found a solution. I just changed
so the second argument would be null if the argument was missing. Hopefully this helps someone else out! Thanks for a great plugin! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
When I use this, it works great. (thank you!) However, my comment_form() function errors out on this function. Here is the error I am getting:
This is the exact function I am using (same as the example above) in functions.php:
And this is where it's erroring, in comments.php at the last line:
Any ideas about what's going wrong? Thank you for the help.