You can modify your theme to automatically put video attachments wherever you want them. I wrote up a little example here https://github.com/kylegilman/video-embed-thumbnail-generator/wiki/Advanced-Template-Editing
I know that a few users have used front end posting plugins to upload videos. In theory there’s no reason why they wouldn’t work. I’ve made an effort to load the plugin’s admin JavaScripts and CSS on the front end if the media upload libraries are loaded on the front end. However, I have not actually done any front end user upload testing myself.
Hi,
thanks you very much. I´m looking forward to your premium version.
Best,
Another question: How have I to transform the shortcode, if I would like to show the post_thumbnail instead of video player, if there´s no video linked to the article?
My example code doesn´t work:
<?php
if ( !has_shortcode( $content, 'kgvid' ) && !has_shortcode( $content, 'fmp' ) ) :
echo do_shortcode('[KGVID]');
else :
twentyfifteen_post_thumbnail();
endif;
?>
That code will only run twentyfifteen_post_thumbnail() if both a KGVID and FMP shortcode are present in the content of the post, which is never going to be true. You could try capturing the output from do_shortcode in a variable and checking to see if it’s empty. If it is, then you show the post thumbnail. I’m assuming you don’t have to echo whatever twentyfifteen_post_thumbnail() outputs. This has not been tested, so use at your own risk.
if ( !has_shortcode( $content, 'kgvid' ) && !has_shortcode( $content, 'fmp' ) ) {
$shortcode = do_shortcode('[KGVID]');
if ( empty($shortcode) ) {
twentyfifteen_post_thumbnail();
}
else {
echo $shortcode;
}
}
I’m only 90% sure that would work. You could also do a query to check if there are videos attached to the post.
if ( !has_shortcode( $content, 'kgvid' ) && !has_shortcode( $content, 'fmp' ) ) {
$args = array(
'post_mime_type' => 'video',
'post_parent' => get_the_ID(),
'post_status' => null,
'post_type' => 'attachment'
);
$video_attachments = get_posts($args);
if ( $video_attachments ) {
echo do_shortcode('[KGVID]');
}
else {
twentyfifteen_post_thumbnail();
}
}
Both shortcodes work. Thank you very much. What is ‘fmp’ exactly?
FMP was the old plugin shortcode which I changed to KGVID two and a half years ago. Unless you were using the plugin before January 2013 you don’t have to worry about it.
Hi,
what can I do, if in a theme the debug error Undefined variable occurs at the line, where I inserted your php template code:
<?php
if ( !has_shortcode( $content, 'kgvid' )) {
echo do_shortcode('[KGVID]');
}
?>
Best,
Usually the name of the undefined variable is part of the error message. If there’s no name, it’s hard to troubleshoot. The only variable in that code is of course $content, which is not necessarily defined by your template. You could try defining it before the if statement:
$content = get_the_content();
or this might work.
if ( !has_shortcode( get_the_content(), 'kgvid' )) {
echo do_shortcode('[KGVID]');
}
None of this has anything to do with my plugin. It’s just WordPress theme programming. And I haven’t tested it so use at your own risk.