Feed to Post's Effect on the Enclosure Link Option

The  Link to Enclosure option works differently when Feed to Post is enabled.

In the core plugin, it makes feed items link to the enclosure link, rather than the original article.

In Feed to Post, the enclosure link is added to the post content, at the beginning as a link.


Changing the Output Format of the Enclosure Link

The output of the enclosure link can be changed through the use of the filter below. The filter accepts 3 arguments, which are:

  • output
    • The current text/HTML output. By default, this will be an <a> tag, with its href link pointing to the enclosure, and its text set to the enclosure link.
  • enclosure
    •  The enclosure link URL for the current imported post being shown on the site.
  • source
    • The ID of the feed source, from which the imported post was imported.

You can use these parameters in your filter function to set the output of the enclosure to whatever you want.

add_filter( 'wprss_ftp_enclosure_output', 'my_enclosure_output', 10, 3 );
function my_enclosure_output( $output, $enclosure, $source ) {
    return "<a href='$enclosure'>Click here to visit the enclosure resource.</a>";
}

The example below shows how all the parameters can be used:

add_filter( 'wprss_ftp_enclosure_output', 'my_enclosure_output', 10, 3 );
/**
* This example changes the output to show a message followed by
* the default output (the <a> link to the enclosure) in bold format,
* for posts imported from the feed source with ID 34 only.
*/
function my_enclosure_output( $output, $enclosure, $source ) {
    // If the feed source is not the feed source with ID 34
    // Return the default output
    if ( $source != 34 ) {
        return $output;
    }
    // Change the enclosure output for feed source ID 34
    $new_output = "This post has an enclosure link: <strong>$output</strong>";
    return $new_output;
}

Changing the position of the enclosure link

By default, the enclosure link output is added to the post content,  before the post’s original content. If you wish to add the output after the content, use the below filter. The filter should return either “before” or “after“.

add_filter('wprss_ftp_enclosure_link_position', 'my_enclosure_position' );
function my_enclosure_position( $position ) {
    return 'after';
}

Still need help? Contact Us Contact Us