I am using the plugin “WP Attachments” to display attached media files on the post.
The plugin does not seem to have the ability to manually call the list in my template and I think the plugin is not really being supported anymore. I checked in the plugin code and I think the line below is the key.
add_filter('the_content', 'wpatt_content_filter');
My coding ability is limited, but I basically changed ‘the_content’ to ‘the_attachedfiles’ and in my functions.php I added:
function the_attachedfiles( $more_link_text = null, $strip_teaser = false ) {
/**
* Filters the post content.
*
* @since 0.71
*
* @param string $content Content of the current post.
*/
$content = apply_filters( 'the_attachedfiles', $content );
$content = str_replace( ']]>', ']]>', $content );
echo $content;
}
Then in my template I added the function I created as so:
<?php the_attachedfiles(); ?>
My question is, can I do this without changing plugin codes? If the plugin gets updated, I’d be forced to manually edit again. So would rather want an alternative.
Secondly, if I’m going to have to change the code in the plugin, then is this the best way and the line I added in the functions.php, I am guessing could also be better.
Any improvements would be appreciated.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Without looking into the plugin, it looks like you could first remove the default placement using:
remove_filter('the_content', 'wpatt_content_filter');
and then call the list function somewhere in your template like this:
echo wpatt_content_filter('');
(the remove_filter would be in functions.php or somewhere near the top of your template, ie before the_content() is called.)
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0