Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save pirate-bot/6e7d69a98d6b97c86bdd8d88cf05d62e to your computer and use it in GitHub Desktop.

Select an option

Save pirate-bot/6e7d69a98d6b97c86bdd8d88cf05d62e to your computer and use it in GitHub Desktop.
link the title to the original article and open them in new window.
<?php
/**
* Plugin Name: Feedzy posts - link the title to the original article and open them in new window
* Description: Link the title of posts imported by Feedzy to the original article
* Version: 1.0
* Author: Themeisle
* Author URI: https://themeisle.com
*/
/**
* Filters the permalink for a post and custom post type.
*
* @param string $url Post link.
* @param object $post Post Object.
* @return string
*/
function feedzy_get_filtered_url( $post ) {
if ( is_admin() ) {
return false;
}
$current_post_meta = get_post_meta( $post->ID, 'feedzy_item_url', true );
if ( ! empty( $current_post_meta ) ) {
return $current_post_meta;
}
return get_permalink( $post );
}
function feedzy_rss_modify_post_links( $title, $id = null ) {
if ( is_admin() || !$id ) {
return $title;
}
$post = get_post( $id );
$url = feedzy_get_filtered_url( $post );
if ( ! empty( $url ) ) {
return '<a href="' . esc_url( $url ) . '" target="_blank">' . $title . '</a>';
}
return $title;
}
add_filter( 'the_title', 'feedzy_rss_modify_post_links', 10, 2 );
function feedzy_rss_modify_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if ( is_admin() ) {
return $html;
}
$post = get_post( $post_id );
$url = feedzy_get_filtered_url( $post );
if ( ! empty( $url ) ) {
return '<a href="' . esc_url( $url ) . '" target="_blank">' . $html . '</a>';
}
return $html;
}
add_filter( 'post_thumbnail_html', 'feedzy_rss_modify_thumbnail_html', 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment