Hi, Larry
Yes, we can use Astra-specific hook to add target="_blank"
attribute to the title's link.
Also I made a hook that adds "Download" link below near to "score" value. Unfortunately it's hard to detect filesize at this point (since the file can be located on another server).
Place this code right below the code that I posted above, in the functions.php
:
// Hook to force search result files to open in new tab
add_filter('astra_the_post_title_before', function($before)
{
if (is_search()) {
// Modify the search result title
$before = preg_replace('/<a\s+href=/', '<a target="_blank" href=', $before);
}
return $before;
});
// Hook to add "Download" link below the excerpt (near the "Score" value)
add_filter('wpfts_se_output', function($a, $post)
{
if ($a && $post) {
if (isset($post['post_type']) && ($post['post_type'] == 'dlp_document')) {
// Add Download button
$shift = (strlen($a['score']) > 0) ? ' wpfts-shift' : '';
$link = '';
$post_id = $post['ID'];
$link_type = get_post_meta($post_id, '_dlp_document_link_type', true);
$file_size = get_post_meta($post_id, '_dlp_document_file_size', true);
$file_id = get_post_meta($post_id, '_dlp_attached_file_id', true);
$link_url = get_post_meta($post_id, '_dlp_direct_link_url', true);
$local_url = false;
if ($link_type === 'file') {
// The attachment post
if ($file_id > 0) {
$link = wp_get_attachment_url($file_id);
}
} elseif ($link_type === 'url') {
// The link
$link = $link_url;
} else {
// Unknown link_type
}
if (strlen($link) > 0) {
$a['link'] = '<a target="_blank" class="wpfts-download-link'.$shift.'" href="'.esc_url($link).'"><span>'.__('Download', 'fulltext-search').'</span></a>';
}
}
}
return $a;
}, 10, 2);
Hope this helps. Thanks you!