Title: Feature: Insert shortcode automatically when using front-end publishing
Last modified: August 30, 2016

---

# Feature: Insert shortcode automatically when using front-end publishing

 *  Resolved [benhartwich](https://wordpress.org/support/users/yoursql719/)
 * (@yoursql719)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/feature-insert-shortcode-automatically-when-using-front-end-publishing/)
 * Hi,
 * is it possible to insert the video automatically above the content at the theme(
   php) without using the shortcode?
 * Is it possbile to work with front end publisher and using your plugin – have 
   you got any expierences with that? Examples: [https://ninjaforms.com/extensions/front-end-posting/](https://ninjaforms.com/extensions/front-end-posting/)
   or [https://wordpress.org/plugins/user-submitted-posts/](https://wordpress.org/plugins/user-submitted-posts/).
   Of course, this would be a paid feature, when it´s possible at the moment and
   I would pay for it!
 * Best,
 * Ben
 * [https://wordpress.org/plugins/video-embed-thumbnail-generator/](https://wordpress.org/plugins/video-embed-thumbnail-generator/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Kyle Gilman](https://wordpress.org/support/users/kylegilman/)
 * (@kylegilman)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/feature-insert-shortcode-automatically-when-using-front-end-publishing/#post-6510352)
 * 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](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.
 *  Thread Starter [benhartwich](https://wordpress.org/support/users/yoursql719/)
 * (@yoursql719)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/feature-insert-shortcode-automatically-when-using-front-end-publishing/#post-6510502)
 * Hi,
 * thanks you very much. I´m looking forward to your premium version.
 * Best,
 *  Thread Starter [benhartwich](https://wordpress.org/support/users/yoursql719/)
 * (@yoursql719)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/feature-insert-shortcode-automatically-when-using-front-end-publishing/#post-6510503)
 * 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;
       	?>
       ```
   
 *  Plugin Author [Kyle Gilman](https://wordpress.org/support/users/kylegilman/)
 * (@kylegilman)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/feature-insert-shortcode-automatically-when-using-front-end-publishing/#post-6510509)
 * 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();
       	}
       }
       ```
   
 *  Thread Starter [benhartwich](https://wordpress.org/support/users/yoursql719/)
 * (@yoursql719)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/feature-insert-shortcode-automatically-when-using-front-end-publishing/#post-6510516)
 * Both shortcodes work. Thank you very much. What is ‘fmp’ exactly?
 *  Plugin Author [Kyle Gilman](https://wordpress.org/support/users/kylegilman/)
 * (@kylegilman)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/feature-insert-shortcode-automatically-when-using-front-end-publishing/#post-6510519)
 * 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.
 *  Thread Starter [benhartwich](https://wordpress.org/support/users/yoursql719/)
 * (@yoursql719)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/feature-insert-shortcode-automatically-when-using-front-end-publishing/#post-6510528)
 * 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,
 *  Plugin Author [Kyle Gilman](https://wordpress.org/support/users/kylegilman/)
 * (@kylegilman)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/feature-insert-shortcode-automatically-when-using-front-end-publishing/#post-6510529)
 * 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.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Feature: Insert shortcode automatically when using front-end publishing’
is closed to new replies.

 * ![](https://ps.w.org/video-embed-thumbnail-generator/assets/icon.svg?rev=2965979)
 * [Videopack](https://wordpress.org/plugins/video-embed-thumbnail-generator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/video-embed-thumbnail-generator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/video-embed-thumbnail-generator/)
 * [Active Topics](https://wordpress.org/support/plugin/video-embed-thumbnail-generator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/video-embed-thumbnail-generator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/video-embed-thumbnail-generator/reviews/)

## Tags

 * [front-end](https://wordpress.org/support/topic-tag/front-end/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [publishing](https://wordpress.org/support/topic-tag/publishing/)

 * 8 replies
 * 2 participants
 * Last reply from: [Kyle Gilman](https://wordpress.org/support/users/kylegilman/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/feature-insert-shortcode-automatically-when-using-front-end-publishing/#post-6510529)
 * Status: resolved