Skip to content

snippet

How to remove “Insert into post” button from media panel

add_action( 'admin_footer-post-new.php', 'firmasite_mediapanel_edit' );
add_action( 'admin_footer-post.php', 'firmasite_mediapanel_edit' );
function firmasite_mediapanel_edit() { ?>
  <script type="text/javascript">
jQuery(document).on("DOMNodeInserted", function(){
		// Removing "Insert into post" button from media panel
		jQuery('a.media-button-insert').filter(function(index) { return jQuery(this).text() === "<?php echo __( 'Insert into post' ); ?>" }).remove();
	});
  </script>
<?php }

This will remove “Insert into post” button from wordpress 3.5 media panel from post post types. It wont remove from page post types. For removing both:
Continue reading

Removing WordPress version from styles and scripts’ enqueue

// Removing wordpress version from script and styles
add_action("wp_head", "firmasite_remove_version_from_assets",1);
function firmasite_remove_version_from_assets(){
	function remove_cssjs_ver( $src ) {
		if( strpos( $src, '?ver=' ) )
			$src = remove_query_arg( 'ver', $src );
		return $src;
	}
	add_filter( 'style_loader_src', 'remove_cssjs_ver', 999 );
	add_filter( 'script_loader_src', 'remove_cssjs_ver', 999 );
}

Continue reading

How to move menu location saves to child themes properly

/* 
 This action copies old theme's menu location saves to 
 new theme if new theme doesnt have saves before. Helpful for child theme switches
*/
add_action( 'after_switch_theme',  'ajx_theme_locations_rescue' );
function ajx_theme_locations_rescue() {
	// bug report / support: http://unsalkorkmaz.com/
	// We got old theme's slug name
	$old_theme = get_option( 'theme_switched' );
	// Getting old theme's settings
	$old_theme_mods = get_option("theme_mods_{$old_theme}");
	// Getting old theme's theme location settings
	$old_theme_navs = $old_theme_mods['nav_menu_locations'];
	// Getting new theme's theme location settings
	$new_theme_navs = get_theme_mod( 'nav_menu_locations' );

	// If new theme's theme location is empty (its not empty if theme was activated and set some theme locations before)
	if (!$new_theme_navs) {
		// Getting registered theme locations on new theme
		$new_theme_locations = get_registered_nav_menus();

		foreach ($new_theme_locations as $location => $description ) {
			// We setting same nav menus for each theme location 
			$new_theme_navs[$location] = $old_theme_navs[$location];
		}

		set_theme_mod( 'nav_menu_locations', $new_theme_navs );

	}
}

Continue reading