Title: Add Insert Button
Last modified: August 21, 2016

---

# Add Insert Button

 *  [wpismypuppet](https://wordpress.org/support/users/wordpressismypuppet/)
 * (@wordpressismypuppet)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/add-insert-button/)
 * It would make this plugin more client friendly if there were a way to auto insert
   the shortcode by clicking a button and selecting which snippet to use from a 
   drop down. If you are interested, here is the code I used:
 *     ```
       // Function to add the snippet button next to the media button
       	function add_snippet_button( $context ){
       		// If we are on a post/page or new post/page
       		if( is_admin() && in_array( basename( $_SERVER['PHP_SELF'] ), array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) {
       			$context .= '<a class="button thickbox" title="Add Snippet" href="#TB_inline?width=400&inlineId=add_snippet_popup_container"><span class="snippet_button_icon"></span>Add Snippet</a>';
       		}
       		return $context;
       	}
       	add_action( 'media_buttons_context', 'add_snippet_button' );
       	// Function to add drop down to a pop up window
       	function add_snippet_button_popup_content() {
       		?>
       		<script>
       			function InsertSnippet(){
       				var snippet_slug = jQuery("#add_snippet_slug").val();
       				if(snippet_slug == ""){
       					alert("Please select a snippet");
       					return;
       				}
       				window.send_to_editor("[snippet slug=\"" + snippet_slug + "\" /]");
       			}
       		</script>
       		<div id="add_snippet_popup_container" style="display:none;">
       			<div class="wrap">
       				<div>
       					<div style="padding:15px 15px 0 15px;">
       						<h3 style="color:#5A5A5A!important; font-family:Georgia,Times New Roman,Times,serif!important; font-size:1.8em!important; font-weight:normal!important;">Insert A Snippet</h3>
       						<span>Select a snippet below to add it to your post or page.</span>
       					</div>
       					<div style="padding:15px 15px 0 15px;">
       						<select id="add_snippet_slug">
       							<option value="">Select a Snippet</option>
       							<?php
       								$args = array(
       									'post_type' => 'snippet',
       									'posts_per_page' => -1,
       									'post_status' => 'publish'
       								);
       								$snippets = get_posts( $args );
       								foreach( $snippets as $snippet ){
       									?>
       									<option value="<?php echo $snippet->post_name; ?>"><?php echo $snippet->post_title; ?></option>
       									<?php
       								}
       							?>
       						</select>
       					</div>
       					<div style="padding:15px;">
       						<input type="button" class="button-primary" value="Insert Snippet" onclick="InsertSnippet();"/>&nbsp;&nbsp;&nbsp;
       						<a class="button" style="color:#bbb;" href="#" onclick="tb_remove(); return false;">Cancel</a>
       					</div>
       				</div>
       			</div>
       		</div>
       		<?php
       	}
       	add_action( 'admin_footer',  'add_snippet_button_popup_content' );
       ```
   
 * I haven’t tested to see if it’s fool proof, but it works well enough for me. 
   I’m hopeful that you’ll go through it and make it better and add it in to the
   next update? Thanks for a great plugin.
 * [http://wordpress.org/plugins/wp-snippets/](http://wordpress.org/plugins/wp-snippets/)

The topic ‘Add Insert Button’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-snippets_b9d1ff.svg)
 * [WP Snippets](https://wordpress.org/plugins/wp-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-snippets/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [wpismypuppet](https://wordpress.org/support/users/wordpressismypuppet/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/add-insert-button/)
 * Status: not resolved