Open paaljoachim opened 9 years ago
I was in contact with StudioPress as well. At this point there is no way for me to hook into their framework's functionality for featured images. They do not make use of the native WordPress functions but implement their own: WordPress' functions provide ways to hook into, their's do not. I am sorry, but it looks like this is not gonna change anytime soon.
To add the featured video above the entry content (perhaps as an option if Genesis is detected?):
add_action( 'genesis_before_entry', 'prefix_add_featured_video_plus' );
function prefix_add_featured_video_plus(){
echo do_shortcode('[featured-video-plus]');
}
What you get in the Sample theme: https://cloudup.com/cixQ33WYZNb
If you want to replace the built in "Featured Image on Content Archives" functionality (and the child theme hasn't overridden that):
add_filter( 'genesis_pre_get_image', 'featured_video_plus_genesis_override', 10, 2 );
function featured_video_plus_genesis_override( $output, $args, $post ){
// only act on archive featured images
if( $args['context'] == 'archive' && has_post_video( $post->ID ) ){
return do_shortcode('[featured-video-plus]');
}else{
return $output;
}
}
YMMV with other Genesis child themes, but this covers the Genesis core functions.
Hope it helps ;-)
Hey Nick
I got the first code snippet to work awesome! The second code gave a few errors when I tested in a local site with DeskTop Server and the Genesis Sample theme.
call_user_func_array:{/Users/joachim/Documents/Websites/newsite.dev/wp-includes/plugin.php:503} ( )
call_user_func_array:{/Users/joachim/Documents/Websites/newsite.dev/wp-includes/widgets.php:1319} ( )
call_user_func_array:{/Users/joachim/Documents/Websites/newsite.dev/wp-includes/plugin.php:213} ( )
But the main thing is that the first code snippet works great! Thank you very much for the code Nick!
Don't use do_shortcode https://kovshenin.com/2013/dont-do_shortcode/
@nciske Comes from Automatic so i assume its spot on. @paaljoachim Tested this and it works when the plugin is activate and deactivated.
add_filter( 'genesis_pre_get_image', 'featured_video_plus_genesis_override', 10, 2 ); function featured_video_plus_genesis_override( $output, $args ){ // only act on archive featured images if( $args['context'] == 'archive' && function_exists('has_post_video') && has_post_video() ) { return the_post_video(); } else { return $output; } }
I stand corrected, thanks for pointing that out @braddalton.
Here's a way to have your shortcode, without the overhead: https://gist.github.com/nciske/3b186cbc91b48d685679
Good stuff @nciske. Are you going to add that to the plugin? Looks like it didn't make it into core.
So we use something like this via the child themes functions file:
add_filter( 'genesis_pre_get_image', 'featured_video_plus_genesis_override', 10, 2 ); function featured_video_plus_genesis_override( $output, $args ){ if( $args['context'] == 'archive' && function_exists('has_post_video') && has_post_video()) { return run_shortcode( 'featured-video-plus' ); } else { return $output; } }
Thanks for investigating! I will probably include this in the next update.
Instead of do_shortcode
or run_shortcode
you can use the following:
return get_the_post_video();
So I just looked into this and am not so sure if I will actually implement this. The problem I see is that the genesis_pre_get_image
filter does a lot more than just filter post thumbnails / featured images - it actually filters all images. You bypassed this by checking the context, but people might choose to show a lot more than a single picture in their post archives.
Agree. I wouldn't add a genesis filter as it's not a genesis specific plugin and you're going to find it won't work in all cases. If you wanted to make a genesis specific plugin for featured videos, you could check out the genesis featured posts widget included in genesis as a starting point.
I got a featured image conditional working for single entries as well.
Hello Tom
Wouldn't you use
add_action('genesis_before_entry','your_function');
rather than
add_filter
Thanks, Brad. Both work, actually, but I'm inferring that it's a best-practice to use add_action?
I think so unless you're using a filter to modify an existing function.
Hi, About the problem size video with new version of Featured Video Plus 2.2.2 and Genesis Framework Perhaps I have found a possible solution, a working demo at this link: http://demotest.pseudoclasse.com/ Genesis Framework + Child sample Plugin: Feature Video Plus, version 2.2.2 In Media settings: "Apply display mode": when viewing single posts and pages.
1) In the file functions.php I add the following code: https://gist.github.com/electricbrick/0489819352c8fe04830e 2) In Feature Video Plus, I opened the file: frontend.min.js and I replaced, from line 225 to line 229 (preload images), the previous version (2.2.0) from line 213 to line 215.
In short, frontend.min.js (NOT minify for practical reasons)
// preload images
// [fvpdata.playicon, fvpdata.loadicon].forEach(function(val) {
// $('body').append($('<img/>', {src: val, alt: 'preload image'}).hide());
// });
// });
//})(jQuery);
// replaced from old version
initFeaturedVideoPlus();
});
})(jQuery);
screenshot showing the problem: http://i.imgur.com/mcVRntA.jpg a demo site, to verify: link removed
My question is: do you think I have done a foolish thing? Do you think it is acceptable as a solution? If you consider that my change is unacceptable, no problem telling me. I have contacted the author of Featured Video Plus.
I managed to get it working (i.e. featured video replaced featured image on single posts and archives) by adding this to my functions.php file and then unchecking 'Include the Featured Image?' in Genesis -> Theme Settings > Content Archives
//* Code to Display Featured Image (and therefore featured video embed)
add_action( 'genesis_before_entry_content', 'featured_post_image', 8 );
function featured_post_image() {
if ( is_singular( 'archive' ) ) return;
the_post_thumbnail('post-image');
}
@pseudomac Is this still a problem? Somehow I missed your reply, and haven't encountered it myself.
I posted the following at the studiopress forum (some time ago):
Hey
I was trying to get the Featured Video Plus plugin https://wordpress.org/plugins/featured-video-plus/ to work with my child theme but it did not function. I e-mailed the author and he told me the following:
The automatic featured image replacement does not work for all themes – the Genesis Framework being one of them (there are many requests for this in the forum). I already was in touch with the developer but they do not intend to change their propitiatory API (they do not use WordPress’ native API).
How would we get the plugin to work with Genesis themes?
The developer is also working on the next version of Featured Video Plus which is located on Github: https://github.com/ahoereth/featured-video-plus/tree/2.0.0
Any ideas as to what we can do about it? What work around can be done?
Thanks.