Skip to content

Instantly share code, notes, and snippets.

View daltonnyx's full-sized avatar
🦥

Quy Truong daltonnyx

🦥
  • Saigon Technology
  • Da Nang
View GitHub Profile
@daltonnyx
daltonnyx / https.php
Created January 10, 2017 09:11
Replace http with https in wp attachments
//Replace http with https in wp attachments
add_action( 'edited_product_cat', 'save_product_cat_banners', 10, 2 );
function have_https_for_media( $url ) {
if ( is_ssl() )
$url = str_replace( 'http://', 'https://', $url );
return $url;
}
add_filter( 'wp_get_attachment_url', 'have_https_for_media' );
$ext = end(explode(".", $data['FileManager']['file']['name']));
@daltonnyx
daltonnyx / mutationObserver.js
Created January 16, 2017 04:27
Mutation Observer
var dataContainer = document.getElementById('data-container');
var observer = new MutationObserver(function (mutations) {
var table = mutations[0].target.getElementsByTagName("TABLE")[0];
if (table != undefined) {
if (table.getElementsByTagName('tbody')[0].innerHTML.trim() == '') {
document.getElementById('upload-nsld').style.display = "none";
}
else {
document.getElementById('upload-nsld').style.display = "inline-block";
@daltonnyx
daltonnyx / form-field-json-cookies.js
Created March 2, 2017 09:06 — forked from zyphlar/form-field-json-cookies.js
Storing & retrieving form fields in a JSON cookie
/* Storing & retrieving form fields in a JSON cookie
* copyright Will Bradley, 2012, released under a CC-BY license
*
* Change all instances of "myform" as necessary.
* Cookie will be stored under the current URL, but
* it won't include any hidden fields, etc.
*/
function setCookie(c_name,value,expireminutes)
{
@daltonnyx
daltonnyx / remove_category_from_title.php
Created March 3, 2017 03:30
Remove “Category:”, “Tag:”, “Author:” from the_archive_title
add_filter( 'get_the_archive_title', function ($title) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
function new_subcategory_hierarchy() {
$category = get_queried_object();
$parent_id = $category->category_parent;
$templates = array();
if ( $parent_id == 0 ) {
// Use default values from get_category_template()
$templates[] = "category-{$category->slug}.php";
<?php
/* =Clean up the WordPress head
------------------------------------------------- */
// remove header links
add_action('init', 'tjnz_head_cleanup');
function tjnz_head_cleanup() {
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Category Feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Post and Comment Feeds
remove_action( 'wp_head', 'rsd_link' ); // EditURI link
jQuery(document).ready(function($){
if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
function wheel(event) {
var delta = 0;
if (event.wheelDelta) delta = event.wheelDelta / 120;
else if (event.detail) delta = -event.detail / 3;
handle(delta);
@daltonnyx
daltonnyx / qtranslate_widget.php
Created April 10, 2017 07:09 — forked from corellian/qtranslate_widget.php
Wordpress qTranslate-X language selector shortcode
/**
* Language Selector Shortcode
*/
function qtranxf_generateLanguageSelectorShortcode() {
global $q_config;
if(is_404()) $url = get_option('home'); else $url = '';
echo PHP_EOL.'<div style="text-transform: uppercase;" class="lang-sel sel-dropdown"><a href="#"><span>'.$q_config['language'].'</span></a><ul>'.PHP_EOL;
foreach(qtranxf_getSortedLanguages() as $language) {
/*
* This is a JavaScript Scratchpad.
*
* Enter some JavaScript, then Right Click or choose from the Execute Menu:
* 1. Run to evaluate the selected text (Ctrl+R),
* 2. Inspect to bring up an Object Inspector on the result (Ctrl+I), or,
* 3. Display to insert the result in a comment after the selection. (Ctrl+L)
*/
const __words = 150;