In Feedzy how do I...

Here are some of the hooks you can use with the Feedzy plugin. Note that some of these customizations may require you to have the premium version of the plugin. To see the list of hooks and filters available for this plugin, click HERE

Note: To apply these customizations, please see the details below.

  • Paste the below code snippets into the custom plugin created using the instructions here.
  • You can view more details about each hook mentioned here on this page

This code works only for the imported posts

function new_excerpt_more($more) {
   $current_post_id = get_the_ID();
   $current_post_meta = get_post_meta($current_post_id);

   if (isset($current_post_meta['feedzy_item_url'][0])) {
      return ' <a href="' . $current_post_meta['feedzy_item_url'][0] . '">Read More</a>';
   }
   return $more;
}
add_filter('excerpt_more', 'new_excerpt_more');

Reverse the order of the items displayed [Widget/shortcode]

function feedzy_feed_items_reverse( $items, $feedURL ){
    $items = array_reverse($items);
    return $items;
}
add_filter('feedzy_feed_items', 'feedzy_feed_items_reverse', 9, 2)

Remove the first item of the items displayed [Widget/shortcode]

function feedzy_feed_items_remove_first( $items, $feedURL ){
    unset($items[0]);
    return $items;
}
add_filter('feedzy_feed_items', 'feedzy_feed_items_remove_first', 9, 2);

Display the title of the website from which the article comes from [Widget/shortcode]

  • add the name of the source after the name of the author
  • add_filter( 'feedzy_author_name', 'feedzy_author_name', 10, 3 );
    function feedzy_author_name( $authorName, $feedURL, $item ) {
    	$source		= 'asdasdfsaf';
    	if ( strpos( strtolower( $feedURL ), 'huffington' ) !== false ) {
    		$source	= 'Huffington Post';
    	}
    	return $authorName . ' ' . $source;
    }
    

    Decrease the cache to the minimum value supported viz. 1 minute [Widget/shortcode]

    add_filter( 'feedzy_get_short_code_attributes_filter', 'feedzy_get_short_code_attributes_filter', 99, 1 );
    function feedzy_get_short_code_attributes_filter( $atts ) {
    $atts['refresh'] = '1_mins';
    return $atts;
    }
    

    Keep HTML in content [Widget/shortcode]

    add_filter( 'feedzy_summary_output', 'feedzy_summary_output', 10, 4 );
        function feedzy_summary_output( $contentSummary, $newLink, $feedURL, $item ) {
            return $item->get_content();
        }
    

    Display all feed items sorted by date independently of the source [Widget/shortcode]

    add_action( 'feedzy_modify_feed_config', 'feedzy_modify_feed_config', 10, 1 );
        function feedzy_modify_feed_config( $feed ) {
            $feed->enable_order_by_date( false );
        }
    
        add_filter( 'feedzy_feed_items', 'feedzy_feed_items', 10, 2 );
        function feedzy_feed_items( $items, $feedURL ) {
            $array = (array) $items;
            return usort( $array, 'feedzy_sort_items' );
        }
    
        function feedzy_sort_items( $a, $b ) {
            return $a->get_date( 'U' ) < $b->get_date( 'U' ) ? 1 : -1;
        }
    

    Display the name of the website as the source of the feeds [Widget/shortcode]

    add_filter( 'feedzy_author_name', 'feedzy_author_name', 10, 3 );
    function feedzy_author_name( $authorName, $feedURL, $item ) {
    	$source		= '/ source';
    	if ( strpos( strtolower( $feedURL ), 'huffington' ) !== false ) {
    		$source	= 'Huffington Post';
    	}
    	return $authorName . ' ' . $source;
    }
    

    Display the name of the source when using multiple sources [Widget/shortcode]

    add_filter( 'feedzy_author_name', 'feedzy_author_name', 10, 3 );
    function feedzy_author_name( $authorName, $feedURL, $item ) {
    	$source		= '';
    	if ( is_array( $feedURL ) ) {
    		// if feedURL is multiple urls.
    		foreach ( $feedURL as $feed ) {
    			if ( strpos( strtolower( $feed ), 'https://www.lavanguardia.com/mvc/feed/rss/home' ) !== false ) {
    				$source	= 'La Vanguardia';
    			}
    			if ( strpos( strtolower( $feed ), 'http://ep00.epimg.net/rss/tags/ultimas_noticias.xml' ) !== false ) {
    				$source	= 'El País';
    			}
    			if ( strpos( strtolower( $feed ), 'http://estaticos.elmundo.es/elmundo/rss/portada.xml' ) !== false ) {
    				$source	= 'El Mundo';
    			}
    			if ( strpos( strtolower( $feed ), 'https://www.europapress.es/rss/rss.aspx' ) !== false ) {
    				$source	= 'Europa Press';
    			}
    		}
    	} else {
    		// if feedURL is a single url.
    	}
    	return $source;<br>}
    

    Remove the time from the feed's post [Widget/shortcode]

    add_filter('feedzy_meta_args', 'feedzy_meta_args', 10, 3);
    		function feedzy_meta_args($metaArgs, $feedURL, $item){
    			unset( $metaArgs['time_format'] );
    			return $metaArgs;
    		}
    

    Add the site name as an element in the feed (instead of author) [Widget/shortcode]

    if ( ! function_exists( 'feedzy_author_name' ) ) {
    	add_filter( 'feedzy_author_name', 'feedzy_author_name', 10, 3 );
    	function feedzy_author_name( $authorName, $feedURL, $item ) {
    		// do something from $feedURL to change $authorName.
    		return $authorName;
    	}
    }
    
    if ( ! function_exists( 'feedzy_author_url' ) ) {
    	add_filter( 'feedzy_author_url', 'feedzy_author_url', 10, 3 );
    	function feedzy_author_url( $authorURL, $authorName, $feedURL ) {
    		// $authorURL = false; // if you don't want to show a link.
    		return $authorURL;
    	}
    }
    

    Make the default image always show [Widget/shortcode]

    if ( ! function_exists( 'feedzy_thumb_output' ) ) {
    	add_filter('feedzy_thumb_output', 'feedzy_thumb_output', 10, 4 );
    	function feedzy_thumb_output($contentThumb, $feedURL, $sizes, $item){
    		$string		= $item->get_content();
    		$img        = html_entity_decode( $string, ENT_QUOTES, 'UTF-8' );
    		$pattern	= '/<img[^>]+\>/i';
    		preg_match_all( $pattern, $img, $matches );
    		$image		= null;
    		if ( isset( $matches[0] ) ) {
    			foreach ( $matches[0] as $match ) {
    				$pattern1 = '/src=[\'"]?([^\'" >]+)[\'" >]/';
    				$link   = '';
    				preg_match( $pattern1, $match, $link );
    				if ( ! empty( $link ) && isset( $link[1] ) ) {
    					$image = $link[1];
    				}
    				break;
    			}
    		}
    
    		if( ! empty( $image ) ) {
    			$contentThumb	= $image;
    		}
    		return $contentThumb;
    	}
    }
    

    Pull the content from the feed into the post [Widget/shortcode]

    add_filter( 'feedzy_content', 'feedzy_content_from_desc' );
    function feedzy_content_from_desc($x){
    return '';
    }
    

    Display full content instead of summary [Widget/shortcode]

    add_filter('feedzy_summary_input', function($summary, $content, $url){
    if ( 'http://feedpress.me/thelifeafter' === $url ) {
    return $content;
    }
    return $summary;
    }, 10, 3);
    
    function bweb_feedzy_add_nofollow( $content ) {
    	return str_replace( '<a href', '<a rel="nofollow" href', $content );
    }
    add_filter( 'feedzy_global_output', 'bweb_feedzy_add_nofollow', 10, 1 );
    

    Disable of stripping of all HTML tags [Widget/shortcode]

    Note: This might affect all attributes, whether they belong to the title, description or content.

    add_action( 'feedzy_modify_feed_config', 'feedzy_modify_feed_config', 10, 1 );
    function feedzy_modify_feed_config( $feed ) {
    	$feed->strip_attributes(false);
    }
    

    Keep HTML in feed items content [Widget/shortcode]

    add_action( 'init', 'feedzy_summary_input_remove', 99 );
    function feedzy_summary_input_remove() {
    	remove_filter('feedzy_summary_input', array( Feedzy_Rss_Feeds::instance()->get_admin(), 'feedzy_summary_input_filter' ), 9);
    }
    

    Change default Feedzy shortcode parameters values [Widget/shortcode]

    function bweb_default_feedzy_shortcode( $out, $pairs, $atts ) {
        $out['max'] = '2';
        $out['maxfeed_title'] = 'no';
        $out['thumb'] = 'auto';
        return $out;
    }
    add_filter( 'shortcode_atts_feedzy_default', 'bweb_default_feedzy_shortcode', 10, 3 )
    
    function bweb_feedzy_remove_link_matches( $matches ) {
        return $matches[2];
    }
    function bweb_feedzy_remove_link( $content, $feedURL ) {
        $pattern= '/<a.*href=\"(https?:\/\/.*)\".*>(.*)<\/a>/iU';
        $content= preg_replace_callback( $pattern, 'bweb_feedzy_remove_link_matches', $content );
        return $content;
    }
    

    We’re now going to use this function with the Feedzy hooks

     
    //Remove the thumnail link
    add_filter( 'feedzy_thumb_output', 'bweb_feedzy_remove_link', 9, 2 );
     
    //Remove the title link
    add_filter( 'feedzy_title_output', 'bweb_feedzy_remove_link', 9, 2 );
     
    //Remove the author link
    add_filter( 'feedzy_meta_output', 'bweb_feedzy_remove_link', 9, 2 );
     
    //Or remove all links at once
    add_filter( 'feedzy_global_output', 'bweb_feedzy_remove_link', 9, 2 );
    

    Do not remove HTML tags from the summary and/or use the item content instead of it description [Widget/shortcode]

    function bweb_summary_input( $description, $content, $feedURL ) {
        //If you want to use the item content as the description. If not, then remove this line
        //If feed don't have content meta, $content is already equal to $description
        $description = $content;
        
        //List of feeds you don't want to remove HTML tags
        $feedList = array (
            'http://www.gumdust.com/feed',
            'http://b-website.com/feed'
            );
        
        //Remove the item HTML tags (as in the default hook) if not in the above list
        if( !in_array( $feedURL, $feedList ) ) {
            $description = trim( strip_tags( $description ) );
        }
        
        //Remove hellip (as in the default hook) 
        //Keep in mind that it will be added later in the plugin render
        $description = trim( chop( $description, '[&hellip;]' ) );
     
        return $description;
    }
    remove_filter( 'feedzy_summary_input', 'feedzy_summary_input_filter', 9 );
    add_filter( 'feedzy_summary_input', 'bweb_summary_input', 10, 3 );
    

    Remove the end hellip [Widget/shortcode]

    function bweb_feedzy_remove_hellip( $content, $feedURL ) {
        $content = str_replace( ' [&hellip;]', '', $content );
        return $content;
    }
    add_filter( 'feedzy_summary_output', 'bweb_feedzy_remove_hellip', 9, 2 );
    
    function bweb_feedzy_readmore( $content, $link, $feedURL ) {
        $content = str_replace( '[&hellip;]', '<a href="' . $link . '" target="_blank">' . __('Read more', 'yourTextDomain') . ' &rarr;</a>', $content );
        return $content;
    }
    add_filter( 'feedzy_summary_output', 'bweb_feedzy_readmore', 9, 3 );
    

    Use your own CSS and dequeue the default plugin CSS style sheet [Widget/shortcode]

    You have to put your CSS rules in your own CSS file.

    function bweb_feedzy_remove_style( $content, $feedURL ) {
        global $feedzyStyle;    
        
        //Style is enqueing when this global var is set to TRUE
        $feedzyStyle = FALSE;
     
        return $content;
    }
    add_filter( 'feedzy_global_output', 'bweb_feedzy_remove_style', 9, 2 );
    

    Use inline CSS and dequeue the default plugin CSS style sheet [Widget/shortcode]

    add_action( 'wp_enqueue_scripts', function() {
    	wp_dequeue_style( 'feedzy-rss-feeds' );
    	wp_deregister_style( 'feedzy-rss-feeds' );
    }, 11 );
    function bweb_feedzy_custom_style( $content, $feedURL ) { 
         
        $customStyle = '
            <style>
                .feedzy-rss .rss_item {
                    border-bottom: 1px solid #eee;
                }
                .feedzy-rss .rss_item .title {
                    font-weight: bold;
                }
                .feedzy-rss .rss_item:after{
                    content:"";
                    display:block;
                    clear: both;
                }
                .feedzy-rss .rss_item .rss_image {
                    float: left;
                    text-decoration: none;
                    border: none;
                }
                .feedzy-rss .rss_item .rss_image span{
                    display:inline-block;
                    background-size: cover;
                    background-position: 50%;
                }
                .feedzy-rss .rss_item .rss_image {
                    margin: 0.3em 1em 0 0;
                }
                .feedzy-rss .rss_item .rss_content small {
                    display: block;
                    font-size: 0.9em;
                    font-style:italic;
                }
            </style>';
            
        $content = $customStyle . $content;
     
        echo $content;
    }
    add_filter( 'feedzy_global_output', 'bweb_feedzy_custom_style', 9, 2 );
    

    Display the feed in a horizontal layout (with scrollbar) [Widget/shortcode]

    function bweb_horizontal_layout( $content, $feedURL ) {
        return '<div class="feedzy-horizontal">' . $content . '</div>';
    }
    add_filter( 'feedzy_global_output', 'bweb_horizontal_layout', 9, 2 );
    
    .feedzy-horizontal {
        overflow-y: hidden;
        overflow-x: scroll;
        width: 100%;
    }
    .feedzy-horizontal .feedzy-rss {
        display: table;
        border-spacing: 15px 0;
        table-layout: fixed;
        width: 100%;
    }
    .feedzy-horizontal .feedzy-rss .rss_item {
        border-bottom: 1px solid #eee;
        width: 300px;
        display: table-cell;
    }
    

    Change cache lifetime for a specific feed [Widget/shortcode]

    function bweb_feedzy_cache_duration( $feedCacheDuration, $feedURL ) {
        if( 'http://b-website.com/feed' == $feedURL )
            return 60*5; //5 minutes
     
        return $feedCacheDuration;
    }
    add_filter( 'wp_feed_cache_transient_lifetime', 'bweb_feedzy_cache_duration', 10, 2 );
    

    Decode item title with HTML Entities [Widget/shortcode]

    function bweb_title_html_entity( $content ) {
        return html_entity_decode( $content );
    }
    add_filter( 'feedzy_title_output', 'bweb_title_html_entity', 9 );
    

    Handle meta feed [Widget/shortcode]

    By default, the line of meta (name of the author and publication date) is displayed through a list of arguments:
    $metaArgs = array(
        'author' => true,
        'date' => true,
        'date_format' => get_option( 'date_format' ),
        'time_format' => get_option( 'time_format' )
    );
    
    You can change these arguments through feedzy_meta_args hook and only display the author’s name or date, select the date and time format.
    function bweb_feedzy_meta_args($metaArgs, $feedURL){
        if( 'http://b-website.com/feed' == $feedURL ) {
            $metaArgs = array(
                        'author' => false,
                        'date' => true,
                        'date_format' => 'j F Y',
                        'time_format' => 'G \h i'
                    );
        }
        return $metaArgs;
    }
    add_filter('feedzy_meta_args', 'bweb_feedzy_meta_args', 9, 2);
    
    Or simpler if you want to change a single parameter. Here the author’s name is hidden for all feeds.
    function bweb_feedzy_meta_hide_author($metaArgs, $feedURL){
        $metaArgs['author'] = false;
        return $metaArgs;
    }
    add_filter('feedzy_meta_args', 'bweb_feedzy_meta_hide_author', 9, 2);
    

    Display item if the content contains specific keywords [Widget/shortcode]

    function bweb_feedzy_feed_item_keywords_content( $continue, $keywords_title, $item, $feedURL ){
        if( 'http://b-website.com/feed' == $feedURL ) {
            $continue = false;
            $keywords_content = array( 'keyword', 'KEYWORD' );
            foreach ( $keywords_content as $keyword ) {
                if ( strpos( $item->get_description(), $keyword ) !== false ) {
                    $continue = true;
                }
            }
        }
        return $continue;
    }
    add_filter('feedzy_item_keyword', 'bweb_feedzy_feed_item_keywords_content', 9, 4);
    

    Display items in a random order [Widget/shortcode]

    function feedzy_feed_items_ramdom( $items, $feedURL ){
        if( 'http://b-website.com/feed' == $feedURL ) {
            shuffle ( $items );
        }
        return $items;
    }
    add_filter('feedzy_feed_items', 'feedzy_feed_items_ramdom', 9, 2);
    

    Change thumbsize and aspect ratio [Widget/shortcode]

    function bweb_feedzy_thumb_aspect_ratio( $sizes, $feedURL ) {
        $sizes = array( 
            'width' => $sizes['width'] * (16/9), 
            'height' => $sizes['height']
        );
        return $sizes;
    }
    add_filter( 'feedzy_thumb_sizes', 'bweb_feedzy_thumb_aspect_ratio', 10, 2 );
    

    Edit the blacklist image name (to prevent fetching smileys) [Widget/shortcode]

    function bweb_feedzy_blacklist_images( $blacklist ) {
        $blacklist[] = 'xxxx';
        return $blacklist;
    }
    add_filter( 'feedzy_feed_blacklist_images', 'bweb_feedzy_blacklist_images' );
    

    Adjust the number of characters to be extracted from every feed [Widget/shortcode]

    add_filter( 'feedzy_content', 'feedzy_content', 10, 2);
    function feedzy_content($content, $item){
        return substr($content, 0, 300);
    }
    

    Import content in Excerpt field as well when importing Feed to Post [Import posts]

    Feedzy has a dedicated feature to import except, however, if you want to manipulate the value of the excerpt and replace or attach something here is a filter that could be used:

    add_filter('feedzy_insert_post_args', 'feedzy_insert_post_args', 10, 5);
    function feedzy_insert_post_args( $args, $item, $post_title, $post_content, $post_excerpt ) {
      // post_excerpt is the first 10 characters of the title
      $args['post_excerpt'] = substr( $post_excerpt, 0, 10 ); return $args;
    }
    

    Here are also a few examples if you're not using a dedicated except field and want to manipulate title or content and part of it import as an excerpt:

    This will import the title to the Excerpt field in your post. 

    add_filter('feedzy_insert_post_args', 'feedzy_insert_post_args', 10, 4);
    function feedzy_insert_post_args( $args, $item, $post_title, $post_content ) {
    	// post_excerpt is the first 10 characters of the title
    	$args['post_excerpt'] = substr( $post_title, 0, 10 );	return $args;
    }
    

    Change 10 to increase or decrease the content length.

    This will import the post's main content(description) to the Excerpt field in your post. 

    add_filter('feedzy_insert_post_args', 'feedzy_insert_post_args', 10, 4);
    function feedzy_insert_post_args( $args, $item, $post_title, $post_content ) {
    	// post_excerpt is the first 10 characters of the title
    	$args['post_excerpt'] = substr( $post_content, 0, 10 );	return $args;
    }
    

    Change author while importing the feeds [Import posts]

    This code will help you to change the author name to another WP user while importing feeds to posts.

    add_filter( 'feedzy_insert_post_args', 'feedzy_insert_post_args', 10, 3 );
    function feedzy_insert_post_args( $args, $item, $post_title ) {
    	$args['post_author'] = 9909; // or whatever the ID of the user is.
    	return $args;
    }
    

    Assigning a different author (existing WordPress user) based on the URL of the Feed [Import posts]

    With the code provided below, you can pass the ID of an existing WordPress user and it will be assigned as an author to all the items imported from that RSS XML Feed.
    For instance, your XML RSS Feed is -  https://www.codeinwp.com/feed/

    And ID of the WordPress user that you want to make the author of the imported items is 9909
    You can add the feed to the source as -  
    https://www.codeinwp.com/feed/?feed_author=9909, and that user will be made the Author of all the imported posts.

    Like this (you can add multiple feeds as a comma-separated list or create a new Category with items and use your feeds with added ?feed_author=ID parameter):

    Code that makes it work:

    function feedzy_insert_post_args_callback( $args, $item, $post_title, $post_content, $index, $job ) {
    	$source = $item['item']->get_feed()->subscribe_url();
    	$source = parse_url( $source );
    	if ( isset( $source['query'] ) ) {
    		parse_str( $source['query'], $params );
    		$feed_author = isset( $params['feed_author'] ) ? (int) $params['feed_author'] : 0;
    		if ( $feed_author && get_user_by( 'ID', $feed_author ) ) {
    			$args['post_author'] = $feed_author;
    	}
    }
    	return $args;
    }
    add_filter( 'feedzy_insert_post_args', 'feedzy_insert_post_args_callback', 10, 6 );
    


    Change import post limit [Import posts]

    This code will help you to change the limit of import posts. In the Feed Import Options, you can select between 10 to 100 but what if you want to import less than 10 posts or more than 100. In this case, you can use the following code.

    function feedzy_items_limit(){
        $feedLimit=array(1,200,400);
        return $feedLimit;
    }
    add_filter('feedzy_items_limit', 'feedzy_items_limit', 9, 1);
    

    In the above code, the numbers inside the array brackets mark the number of parameters the function receives. After adding this code, you will find these parameters under the "How many feed items to process from the feed" dropdown while importing the feed. You can select an option here and proceed further.

    Do not import post if the content is less than 100 characters long [Import posts]

    This code will help you to exclude the posts if they are small:

    add_filter( 'feedzy_insert_post_args', 'feedzy_insert_post_args', 10, 4 );
    function feedzy_insert_post_args( $args, $item, $title, $content ) {
    	// do not insert if content is less than 100 characters long.
    	// empty title and content prevents WP from inserting a post.
    	if ( strlen( $content ) < 100 ) {
    		$args['post_title'] = '';
    		$args['post_content'] = '';
    	}
    	return $args;
    }
    

    Note: When the posts will be imported, the count will remain original but there will be less number of posts imported. 

    Link Post Title to the initial post source URL [Import posts]

    This code will help you to link the post title to the URL of the original post:

    add_filter( 'post_link', function( $url, $post ) {
    	if ( is_admin() ) {
    		return $url;
    	}
    
    	$id = $post;
    	if ( is_object( $post ) ) {
    		$id = $post->ID;
    	}
    
    	$feedzy = get_post_meta( $id, 'feedzy', true );
    	if ( intval( $feedzy ) === 1 ) {
    		return get_post_meta( $id, 'feedzy_item_url', true );
    	}
    	return $url;
    
    }, 99999, 2 );
    

    Extracting information from CDATA format [Widget/shortcode]

    This method works only with the shortcode approach

    add_filter( 'feedzy_extract_from_custom_tag', function( $thePrice, $extract, $item, $sc ) {
    	if($sc['feeds'] == 'CUSTOM_URL' && $extract === 'price' ){
    		$data = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'summary');
    		$html = $data[0]['data'];
    		$doc = new DOMDocument();
    		libxml_use_internal_errors( false );
    		$doc->loadHTML( $html );
    		$ps = $doc->getElementsByTagName('p');
    		if(count( $ps ) > 0){
    			$array = explode('<br />', nl2br( $ps[0]->nodeValue));
    
    			if( ! empty( trim( $array[3] ) ) ){
    				$thePrice = trim( $array[3] );
    			}
    		}
    	}
    	return $thePrice;
    }, 10, 4);
    

    Displaying the source in the metadata [Widget/shortcode]

    When displaying the feeds directly from the URL, the source is not mentioned in the post metadata by default.
    This can be added by using the following code.

    add_filter( 'feedzy_meta_date', function( $date, $date_time, $feed_url, $item ) {
    	$source = $item->get_feed()->get_title();
    	$permalink = $item->get_feed()->get_permalink();
    	$date_format = get_option( 'date_format' );
    	$data = '';
    	if ( $source ) {
    		$data .= __( 'Source: ', 'feedzy-rss-feeds' );
    		if ( $permalink ) {
    			$data .= '<a href="' . $permalink . '" target="_blank">' . $source . '</a> - ';
    		} else {
    			$data .= $source . ' - ';
    		}
    	}
    	return $data . __( 'on', 'feedzy-rss-feeds' ) . ' ' . date_i18n( $date_format, $date_time ) . ' ';
    }, 10, 4 );
    

    Manipulate the value of a custom tag [Import posts]

    Custom tags are only available for Developer and Agency packages and here is a filter that allows manipulating the data of a custom tag when importing it. In the example below we're using a tag [#item_custom_media:description[len:50]] - and we also want to change the text that we get from it so we can use our imagination here and modify the text in whatever way we need.

    function callback_feedzy_custom_magic_tag_format( $text, $tag, $feed, $index ) {
      if ( '[#item_custom_media:description[len:50]]' === $tag ) {
        $text = $text . '...';
      }
      return $text;
    }
    add_filter( 'feedzy_custom_magic_tag_format', 'callback_feedzy_custom_magic_tag_format', 10, 4 );
    

    Eliminate duplicate feed items [Import Posts]

    When remove duplicates option is enabled in Import settings - we check for items by their title and URLs and if both match we treat an item as a duplicate and we don't import it. It happens that when using multiple feeds the URLs of items are different and you might want to compare only the title of items. To cover this use case we have a custom filter. [Please keep in mind that some items might have a matching title but not necessarily be unique and in such case one of them won't be imported]

    You can use this filter to achieve elimination of duplicates by title: 

    add_filter(
    	'feedzy_feed_items',
    	function ( $items ) {
    		$exclude_duplicates = array();
    		$filtered_items       = array();
    		foreach ( $items as $key => $item ) {
    			$title = $item->get_title();
    			if ( in_array( $title, $exclude_duplicates, true ) ) {
    				continue;
    			}
    			$exclude_duplicates[] = $title;
    			$filtered_items[ $key ] = $item;
    		}
    		return $filtered_items;
    	},
    	99
    );
    

    Eliminate duplicate feed items [Shortcode]

    When you have a large set of feed URLs that you would like to display, there is a common issue with removing the duplicates based on their URLs.

    You can use this code snippet to achieve this: 

    function tifd_feedzy_remove_duplicates( $items, $feedURL ) {
    	$uniques = array();
    	foreach ( $items as $item ) {
    		if ( isset( $uniques[ strval( md5( $item->get_permalink() ) ) ] ) ) {
    			continue;
    		}
    		$uniques[ md5( $item->get_permalink() ) ] = $item;
    	}
    	return array_values( $uniques );
    }  
    add_filter( 'feedzy_feed_items', 'tifd_feedzy_remove_duplicates', 10, 2 );
    

    Feedzy sets first found image as the featured image of an imported post. If your feed returns some unexpected image as the first one (for example author's image) and you want to change this behavior you can use the filter above to manipulate which of the returned images is used as a featured image of the imported post. You need to change number [1] in line $image = $matches[1]; depending on which image you want to return.

    You can use this code snippet to achieve this: 

    add_filter(
    	'feedzy_retrieve_image',
    	function ( $thumbnail, $item ) {
    		$string  = $item->get_content();
    		$img     = html_entity_decode( $string, ENT_QUOTES, 'UTF-8' );
    		$pattern = '/<img[^>]+\>/i';
    		preg_match_all( $pattern, $img, $matches );
    
    		$image = null;
    		if ( isset( $matches[0] ) ) {
    			$matches = reset( $matches );
    			$image   = $matches[1];
    			$pattern = '/< *img[^>]*src *= *["\']?([^"\']*)/';
    			preg_match( $pattern, $image, $link );
    			if ( ! empty( $link ) && isset( $link[1] ) ) {
    				$thumbnail = $link[1];
    			}
    		}
    		return $thumbnail;
    	},
    	99,
    	2
    );
    
    function bweb_feedzy_remove_link_matches( $matches ) {
        return $matches[2];
    }
    
    add_filter('feedzy_insert_post_args', 'feedzy_insert_post_args', 10, 4);
    function feedzy_insert_post_args( $args, $item, $post_title, $post_content ) {
    	$pattern= '/<a.*href=\"(https?:\/\/.*)\".*>(.*)<\/a>/iU';
    	$args['post_content'] = preg_replace_callback( $pattern, 'bweb_feedzy_remove_link_matches', $post_content );
    	return $args;
    }
    
    function bweb_feedzy_add_nofollow_to_links( $matches ) {
        return '<a rel="nofollow" href="' . esc_url($matches[1]) . '">' . esc_html($matches[2]) . '</a>';
    }
    
    add_filter('feedzy_insert_post_args', 'feedzy_insert_post_args', 10, 4);
    function feedzy_insert_post_args( $args, $item, $post_title, $post_content ) {
        $pattern = '/<a\s+href=["\'](https?:\/\/.*?)["\'].*?>(.*?)<\/a>/i';
       
        $args['post_content'] = preg_replace_callback( $pattern, 'bweb_feedzy_add_nofollow_to_links', $post_content );
        return $args;
    }
    
    Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

    Still need help? Contact Us Contact Us