Skip to content

Instantly share code, notes, and snippets.

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

Cuong Vuong cuongtobi

🏠
Working from home
View GitHub Profile
@cuongtobi
cuongtobi / to_slug.php
Created July 1, 2022 09:19
convert string to slug
<?php
function to_slug($str) {
$str = trim(mb_strtolower($str));
$str = preg_replace('/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/', 'a', $str);
$str = preg_replace('/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/', 'e', $str);
$str = preg_replace('/(ì|í|ị|ỉ|ĩ)/', 'i', $str);
$str = preg_replace('/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/', 'o', $str);
$str = preg_replace('/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/', 'u', $str);
$str = preg_replace('/(ỳ|ý|ỵ|ỷ|ỹ)/', 'y', $str);
$str = preg_replace('/(đ)/', 'd', $str);
@cuongtobi
cuongtobi / wp_custom_page_rewrite_url.php
Created May 27, 2022 08:51
Wordpress custom page rewrite url
<?php
add_rewrite_rule('^(custom-page)/([^/]*)/?', 'index.php?pagename=$matches[1]&custom_var=$matches[2]', 'top');
function custom_query_vars_filter($vars) {
$vars[] .= 'custom_var';
return $vars;
}
add_filter('query_vars', 'custom_query_vars_filter');
// flush_rewrite_rules();
@cuongtobi
cuongtobi / reset.css
Created April 16, 2022 06:35
Reset css
html,
body,
p,
ol,
ul,
li,
dl,
dt,
dd,
blockquote,
@cuongtobi
cuongtobi / GitCommitEmoji.md
Created April 6, 2022 09:59 — forked from parmentf/GitCommitEmoji.md
Git Commit message Emoji
@cuongtobi
cuongtobi / lazy-load-google-adsense-and-google-analytics.js
Created April 4, 2022 08:35
Javascript lazy load google adsense and google analytics
var lazyLoad = false;
function onLazyLoad() {
if (lazyLoad === true) return;
lazyLoad = true;
document.removeEventListener('scroll', onLazyLoad);
document.removeEventListener('mousemove', onLazyLoad);
document.removeEventListener('mousedown', onLazyLoad);
document.removeEventListener('touchstart', onLazyLoad);
@cuongtobi
cuongtobi / lazy-load-images.js
Last active April 4, 2022 08:31
Javascript lazy load images
window.addEventListener('DOMContentLoaded', function () {
var observer,
options = {
rootMargin: '0px',
threshold: 0.05
},
allTheLazyImages = document.querySelectorAll('.lazy');
function lazyLoader(e) {
e.forEach(function (e) {
window.addEventListener('DOMContentLoaded', function () {
window.focus();
window.addEventListener('blur', function () {
setTimeout(function () {
if (document.activeElement.tagName === 'IFRAME') {
console.log('clicked');
}
});
});
@cuongtobi
cuongtobi / 404-redirect-to-homepage.php
Created March 24, 2022 10:26
Wordpress 404 redirect to homepage
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . get_bloginfo('url'));
exit();
?>
@cuongtobi
cuongtobi / g-recaptcha-js.js
Created March 24, 2022 09:42
Google recaptcha js
window.onScriptLoad = function () {
// this callback will be called by recaptcah/api.js once its loaded. If we used
// render=explicit as param in script src, then we can explicitly render reCaptcha at this point
// element to "render" invisible captcha in
var htmlEl = document.querySelector('.g-recaptcha');
// option to captcha
var captchaOptions = {
sitekey: '6Lck',