Skip to content

Instantly share code, notes, and snippets.

View joychetry's full-sized avatar
🏠
Working from home

Joy Chetry joychetry

🏠
Working from home
View GitHub Profile
@joychetry
joychetry / functions.php
Created October 30, 2024 18:23
Copy Taxonomy Data WordPress
// Define your source and target taxonomies, as well as the post type (optional)
$source_taxonomy = 'project-category'; // Source taxonomy
$target_taxonomy = 'project-tag'; // Target taxonomy
$post_type = 'project'; // Replace with your post type, or leave empty for all
// Function to copy terms from the source taxonomy to the target taxonomy
function copy_taxonomy_terms( $source_taxonomy, $target_taxonomy, $post_type = '' ) {
// Step 1: Get all posts in the specified post type with terms from the source taxonomy
$args = array(
'post_type' => $post_type ?: 'any', // Use 'any' for all post types if not specified
@joychetry
joychetry / functions.php
Created July 30, 2024 05:49
Dark Mode Switch
/*!
* Dark Mode Switch v1.0.1 (https://github.com/coliff/dark-mode-switch)
* Copyright 2021 C.Oliff
* Licensed under MIT (https://github.com/coliff/dark-mode-switch/blob/main/LICENSE)
*/
var darkSwitch=document.getElementById("darkSwitch");window.addEventListener("load",(function(){if(darkSwitch){initTheme();darkSwitch.addEventListener("change",(function(){resetTheme()}))}}));function initTheme(){var darkThemeSelected=localStorage.getItem("darkSwitch")!==null&&localStorage.getItem("darkSwitch")==="dark";darkSwitch.checked=darkThemeSelected;darkThemeSelected?document.body.setAttribute("data-theme","dark"):document.body.removeAttribute("data-theme")}function resetTheme(){if(darkSwitch.checked){document.body.setAttribute("data-theme","dark");localStorage.setItem("darkSwitch","dark")}else{document.body.removeAttribute("data-theme");localStorage.removeItem("darkSwitch")}}
@joychetry
joychetry / functions.php
Created July 30, 2024 05:47
SMTP Test in WordPress Dashboard
add_action('admin_menu', 'smtp_test_email_menu');
function smtp_test_email_menu() {
add_menu_page(
'SMTP Test Email', // Page title
'SMTP Test Email', // Menu title
'manage_options', // Capability
'smtp-test-email', // Menu slug
'smtp_test_email_page' // Callback function
);
@joychetry
joychetry / functions.php
Last active July 29, 2024 12:53
WordPress Custom Gmail SMTP
//In functions.php
//Custom SMTP
/** Custom SMTP Settings */
function custom_phpmailer_smtp( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = SMTP_HOST;
$phpmailer->SMTPAuth = true;
$phpmailer->Port = SMTP_PORT;
$phpmailer->Username = SMTP_USER;
@joychetry
joychetry / terminal
Last active June 29, 2024 07:58
Update maxmemory and maxmemory-policy in Redis Server
No need of changing any thing in the .conf file just follow the following steps
Step 1: First check whether redis-server is working or not
$ redis-cli
127.0.0.1:6379> ping
PONG
if the reply is PONG then your server is working absolutely fine.
Step 2: To get the current max memory run the following commands:
@joychetry
joychetry / check-and-delete-media.php
Created June 26, 2024 19:05
Check Files and Delete Media Entries
<?php
/*
Plugin Name: Check and Delete Media
Description: Check all media items and delete entries if the images are not in the uploads folder. Display the total number of missing files and delete on button click.
Version: 1.2
Author: Joy Chetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
@joychetry
joychetry / wp-config.php
Created June 26, 2024 15:59
Object Cache Pro in Multiple Website in Same Server
define('WP_REDIS_CONFIG', [
'token' => 'your_token_key',
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0, // change for each site
'maxttl' => 3600 * 24 * 7, // 7 days
'timeout' => 1.0,
'read_timeout' => 1.0,
'prefetch' => true,
'split_alloptions' => true,
@joychetry
joychetry / wp-config.php
Created June 25, 2024 19:25
Wipe Clean WordPress Plugin
Before we explain the detailed way, there is a quick solution to get rid of WooCommerce data completely.
Open your site’s wp-config.php file through FTP or File Manager.
Scroll towards the bottom, add this line:
define(‘WC_REMOVE_ALL_DATA’, true);
Make sure to use straight quotation marks and add the code on its own line above the / That’s all, stop editing! Happy blogging. / line in the file, around line 76 of the file.
Save the file to the server.
Press “Deactivate” > “Delete” to remove the plugin from your admin panel.
You can again go back and remove the above code from the wp-config file. Then when you deactivate and delete WooCommerce it will remove all of its data from your WordPress database.
@joychetry
joychetry / style.css
Created May 21, 2024 12:59
Scrollbar
::-webkit-scrollbar{
width: 4px;
border-radius: 4px;
margin-left: 4px;
}
::-webkit-scrollbar-track{
background: rgba(0, 0, 0, 0.1);
}
@joychetry
joychetry / single.php
Created April 16, 2024 08:28
Prompt native sharing options inside a post page
<script>
document.addEventListener('DOMContentLoaded', function() {
// Click event listener for images with class 'shareLink'
const images = document.querySelectorAll('.shareLink');
images.forEach(function(image) {
image.addEventListener('click', function() {
const link = document.URL;
// Check if Web Share API is supported
if (navigator.share) {