Skip to content

Instantly share code, notes, and snippets.

View khoipro's full-sized avatar
💭
#devops #wordpress #vuejs #docker

Nguyễn Minh Khôi khoipro

💭
#devops #wordpress #vuejs #docker
View GitHub Profile
@khoipro
khoipro / functions.php
Created June 21, 2025 02:45
Reject any comment contain URLs, disable comment field URL
<?php
// Sử dụng: paste đoạn code vào trong file theme functions.php
// Không cần nếu bạn đã tắt comment trên web
function codetot_prevent_urls_in_comment_content( $commentdata ) {
$comment_content = $commentdata['comment_content'];
$url_pattern = '/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/i';
if ( preg_match( $url_pattern, $comment_content ) ) {
wp_die(
@khoipro
khoipro / sample-lazyload-sections.php
Last active June 13, 2025 14:33
Sample section lazyload using <noscript> - DRAFTING
<?php
/** Drafting **/
add_filter('the_content', 'codetot_lazyload_home_sections', 1000);
function codetot_lazyload_home_sections( $content ) {
$front_page_id = get_option('page_on_front');
if ( ! is_page( $front_page_id ) ) {
return $content;
}
@khoipro
khoipro / functions.php
Last active May 22, 2025 19:04
Remove Unnecessary Code in WordPress Header
// Remove Meta Generator: <meta name="generator" content="WordPress x.x" />
// and <meta name="generator" content="WooCommerce x.x.x" />
remove_action('wp_head', 'wp_generator');
// Remove the EditURI/RSD
// Like: <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://localhost/wp/xmlrpc.php?rsd" />
remove_action ('wp_head', 'rsd_link');
// Remove it if you don't know what is Windows Live Writer
// <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://localhost/wp/wp-includes/wlwmanifest.xml" />
@khoipro
khoipro / my.cnf
Last active January 21, 2025 01:51
Tweak MySQL for better performance
# CPU = 4
# RAM = 8GB
# Website = WordPress, WooCommerce, >1k products
# Cache = W3 Total Cache
[mysql]
port = 3306
[mysqld]
performance_schema = ON
@khoipro
khoipro / free.txt
Last active November 4, 2024 05:01
Free download some leaked keys
https://rankmath.com/download/510590/seo-by-rank-math-pro.zip?username=thachpham&api_key=e5cd5c67cafe7d5e7315558011457319
<?php
/**
* Use redis cache
*
* @package codetot-optimization
* @author codetot
* @since 0.0.1
*/
class Sample_Redis_Cache {
@khoipro
khoipro / sample.html
Last active November 2, 2024 13:43
Using lazysizes to improve image load. - Sample by CODETOT @khoipro
<!doctype html>
<html lang="en">
<head>
<link rel="preconnect" href="https://cdnjs.cloudflare.com" crossorigin>
<link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/lazysizes/5.3.2/lazysizes.min.js" as="script" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/lazysizes/5.3.2/lazysizes.min.js">
</head>
<body>
<div class="in-first-view">
<img src="image-1.jpg" width="640" height="480" alt="">
@khoipro
khoipro / regex.md
Created September 30, 2024 04:16
Insert data into wp_options without adding option_id

Sample data

INSERT INTO `qUj_options` (`option_id`, `option_name`, `option_value`, `autoload`) VALUES
('nav_menu_options',	'a:2:{i:0;b:0;s:8:\"auto_add\";a:0:{}}',	'yes'),
('_options_en_US_h_section1_label',	'field_66ac4f4535309',	'off'),
('_options_en_US_h_section1_title',	'field_66ac4f523530a',	'off'),
('_options_en_US_h_section13_preview',	'field_66f15be9ceab9',	'off');
@khoipro
khoipro / slider.js
Last active September 14, 2024 00:09
Load swiper slides lazyload (with <noscript> tag) for each slide
import { select, selectAll, hasClass, removeClass, loadNoscriptContent } from 'lib/dom'
import Swiper, { Navigation } from 'swiper'
export default el => {
const sliderEl = select('.js-slider', el)
const slideEls = selectAll('.swiper-slide', el)
if (sliderEl) {
const swiper = new Swiper(sliderEl, {
freeMode: true,
@khoipro
khoipro / functions.php
Created September 11, 2024 14:46
Sample extends with a plugin Simple Sticky Contacts (v0.0.6+)
<?php
// Sample extends with a plugin Simple Sticky Contacts (v0.0.6+)
add_action('init', 'codetot_theme_ssc_init', 10);
function codetot_theme_ssc_init() {
add_filter('ssc_icons', 'codetot_theme_ssc_icons');
add_filter('ssc_get_fields', 'codetot_theme_ssc_fields');
add_filter('ssc_svg_icon_map', 'codetot_theme_ssc_icon_map');
}