I’m running the YouTube Video Fetcher plugin and it fetches youtube videos and displays it on your website. However, instead of displaying the video after the post, I want to hook the code into a custom container.

Here is the function in the plugin used to display the video after the post:

//The below function is used to display the video after the post.
function append_the_video($content){
    return $content.youtube_video();
add_filter('the_content', 'append_the_video');

I tried swapping out the following line:

add_filter('the_content', 'append_the_video');

with this line but it is not working:

add_action('my_custom_hook_name', 'append_the_video');


Something like what you are doing should work but I think you have a couple of things going wrong.

First, it sounds like you've hacked the plugin. Don't do that, just remove the callback from the the_content hook.

In your theme's functions.php add:

remove_filter('the_content', 'append_the_video');

The youtube_video() function depends on the $post variable. That means it is an essentially "Loop-only" function. You can't move it outside the Loop if that is what you are trying to do. It won't work correctly.

You can run it in a different location by adding your own callback to the_content.

function my_prepend_the_video($content){
    return youtube_video().$content;
add_filter('the_content', 'my_prepend_the_video');

And of course, you can add other markup if you need to.

Related Wordpress search:

, , , , , ,

Wordpress related questions and answers: