Skip to content

Instantly share code, notes, and snippets.

@bagerathan
bagerathan / useful-sql-queries.sql
Last active August 22, 2021 15:09
[Useful SQL queries] #wp #sql
/* remove meta field */
DELETE FROM wp_postmeta WHERE meta_key = 'YourMetaKey';
/* batch deleted spam comments */
DELETE FROM wp_comments WHERE wp_comments.comment_approved = 'spam';
/* batch deleted all unapproved comments */
DELETE FROM wp_comments WHERE comment_approved = 0;
/* disable comments on older posts */
@bagerathan
bagerathan / show-cheapest-option.php
Created August 22, 2021 14:44
[Only show cheapest shipping option] #woo
/**
* Only display the cheapest shipping rate
*/
function my_only_show_cheapest_shipping_rate( $rates, $package ) {
$cheapest_method = '';
// Loop through shipping rates
if ( is_array( $rates ) ) :
foreach ( $rates as $key => $rate ) :
@bagerathan
bagerathan / cleanup-wordpress-header.php
Created August 22, 2021 14:37
[Cleanup WordPress header] #wp
add_action('init', 'evolution_remheadlink');
function evolution_remheadlink(){
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
@bagerathan
bagerathan / disable-oembeds.php
Created August 22, 2021 14:36
[Disable oEmbeds] #wp
/**
* Disable embeds on init.
*
* - Removes the needed query vars.
* - Disables oEmbed discovery.
* - Completely removes the related JavaScript.
*
* @since 1.0.0
*/
function evolution_disable_embeds_init() {
@bagerathan
bagerathan / remove-emoji.php
Created August 22, 2021 14:35
[Remove emoji] #wp
/**
* Disable the emojis
*/
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
@bagerathan
bagerathan / add-custom-fee-to-cart.php
Last active December 11, 2022 08:13
[WooCommerce Snippets] helpful snippets for WooCommerce development #woo
function woo_add_cart_fee() {
global $woocommerce;
if ( is_cart() ) {
$woocommerce->cart->add_fee( __('Custom', 'woocommerce'), 5 );
}
}
add_action( 'woocommerce_before_cart_table', 'woo_add_cart_fee' );
@bagerathan
bagerathan / popular-posts.php
Created August 22, 2021 06:50
[Popular posts based on post view] #wp
@bagerathan
bagerathan / featured-image-in-quick-edit.php
Created August 22, 2021 04:36
[Featured image in quickedit] #wp
@bagerathan
bagerathan / update-cart.html
Created August 22, 2021 04:02
[Update cart without button] #woo
<!-- Update woocommerce cart after quantity change without clicking the button -->
<style>
.woocommerce button[name="update_cart"],
.woocommerce input[name="update_cart"] {
display: none;
}
</style>
<script>
@bagerathan
bagerathan / disable-create-new-post.php
Created August 22, 2021 03:59
[Disable create new post] #wp
register_post_type( 'custom_post_type_name', array(
'capability_type' => 'post',
'capabilities' => array(
'create_posts' => false, // Removes support for the "Add New" function ( use 'do_not_allow' instead of false for multisite set ups )
),
'map_meta_cap' => true, // Set to `false`, if users are not allowed to edit/delete existing posts
));