Skip to content

Instantly share code, notes, and snippets.

View Asikur22's full-sized avatar
๐Ÿ’œ
Web Developer | In Love with WordPress

Asiqur Rahman Asikur22

๐Ÿ’œ
Web Developer | In Love with WordPress
View GitHub Profile
@Asikur22
Asikur22 / hooks.php
Last active March 19, 2022 19:19
Increase WP Login Cookies Time #wp #login #rememberme
// For Admin 4months orther 2months
add_filter( 'auth_cookie_expiration', function ( $time, $user_id ) {
$user = new WP_User( $user_id );
if ( ! empty ( $user->roles ) && in_array( 'administrator', $user->roles, true ) ) {
return MONTH_IN_SECONDS * 4;
}
return MONTH_IN_SECONDS * 2;
}, 99, 2 );
@Asikur22
Asikur22 / functions.php
Created February 12, 2022 04:56
Set Single template for Taxonomy Term #single-taxonomy-term.php
add_filter( 'template_include', function ( $template ) {
if ( is_singular( 'POST_TYPE_NAME' ) ) {
$term = get_the_terms( null, 'TAXONOMY_NAME' );
$new_template = locate_template( array( 'TEMPLATE_NAME.php' ) );
if ( isset( $term[0]->slug ) && $term[0]->slug == 'TERM_NAME' && '' != $new_template ) {
return $new_template;
}
}
return $template;
@Asikur22
Asikur22 / functions.php
Last active February 4, 2022 06:10
WP Add Admin Page
/*
* Add Admin Hidden Page.
*/
add_action( 'admin_menu', function () {
add_submenu_page(
'',
__( 'Trade License Image', 'text-domain' ),
__( 'Trade License Image', 'text-domain' ),
'manage_options',
'trade-license-image',
@Asikur22
Asikur22 / watermark-image-uploads.php
Created January 1, 2022 04:49 — forked from Viper007Bond/watermark-image-uploads.php
Watermark WordPress Image Uploads
<?php
/*
* Plugin Name: WordPress.com Watermark Image Uploads
* Author: Alex Mills
* Author URI: http://automattic.com/
*/
class WPcom_Watermark_Uploads {
public $watermark;
@Asikur22
Asikur22 / functions.php
Created December 30, 2021 14:28
WP Change Site Language
add_action( 'wp', function () {
is_admin() or switch_to_locale( 'en_US' );
} );
@Asikur22
Asikur22 / functions.php
Created December 27, 2021 10:52
Bulk Add Term Meta
/*
* Bulk Add Term Meta
*/
function theme_create_term_meta( $term_id, $tt_id, $taxonomy ) {
if ( $taxonomy == 'rtcl_category' ) {
$types = array( 'sell', 'buy', 'rent' );
if ( ! empty( $types ) ) {
foreach ( $types as $type ) {
add_term_meta( $term_id, '_rtcl_types', $type );
}
@Asikur22
Asikur22 / functions.php
Created December 8, 2021 12:00
Register jQuery Script
/*
* Register jQuery Script
*/
function wp98_theme_jquery_scripts() {
wp_deregister_script( 'jquery' );
wp_enqueue_script( 'jquery', '//code.jquery.com/jquery-1.11.0.min.js', false, '1.11', true );
wp_deregister_script( 'jquery-migrate' );
wp_enqueue_script( 'jquery-migrate', '//code.jquery.com/jquery-migrate-1.2.1.min.js', array( 'jquery' ), '1.2.1', true );
}
@Asikur22
Asikur22 / functions.php
Created November 14, 2021 12:12
WP Blocks Color Palettes
/*
* WP Blocks Color Palettes
*/
function aa_theme_block_color_palette() {
add_theme_support( 'editor-color-palette', array(
array(
'name' => 'Primary',
'slug' => 'primary',
'color' => '#478abd',
),
@Asikur22
Asikur22 / functions.php
Last active January 28, 2022 10:42
Remove WooCommerce Scripts & Styles on Other Page
/**
* Optimize WooCommerce Scripts
* Updated for WooCommerce 2.0+
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
function customizable_blogily_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
//first check that woo exists to prevent fatal errors
@Asikur22
Asikur22 / scripts.js
Created November 1, 2021 11:16
Vanilla JS Slide Up/Down
var mainMenu = document.querySelector( '#menu-primary-navigation' );
document.querySelector( '.mainMenuToggler' ).addEventListener( 'click', function ( event ) {
event.preventDefault();
/** Slide down. */
if ( !mainMenu.classList.contains( 'active' ) ) {
/** Show the mainMenu. */
mainMenu.classList.add( 'active' );
mainMenu.style.height = "auto";