Skip to content

Instantly share code, notes, and snippets.

@bagerathan
bagerathan / popular-posts.php
Created August 22, 2021 06:50
[Popular posts based on post view] #wp
@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 / 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 / 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 / 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 / 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 / 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 / restrict-access.php
Created August 23, 2021 04:25
[Restrict access to custom posts based on role] #wp
//create a new role
function psp_add_project_management_role() {
add_role('psp_project_manager',
'Project Manager',
array(
'read' => true,
'edit_posts' => false,
'delete_posts' => false,
'publish_posts' => false,
@bagerathan
bagerathan / compress-files.htaccess
Last active August 23, 2021 06:28
[htaccess] #web
<IfModule mod_deflate.c>
# Compress all output labeled with one of the following MIME-types
# (for Apache versions below 2.3.7, you don't need to enable `mod_filter`
# and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines
# as `AddOutputFilterByType` is still in the core directives).
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
@bagerathan
bagerathan / wordpress-conditions.php
Last active June 16, 2022 06:04
[WordPress conditions] #wp
<?php
is_home() //Checks if the blog post index is being displayed. This may or may not be your home page as well.
is_front_page() //Checks if your home page is being displayed. This works whether your front page settings are set up to display blog posts (i.e. blog index) or a static page.
is_single() //Checks to see whether any type of single post is being displayed (excluding attachments).
is_attachment() //Checks if an attachment is displayed.