Skip to content

Instantly share code, notes, and snippets.

@dksign
dksign / wp-svg-upload.php
Last active October 3, 2020 22:16
Add support for svg upload in Wordpress.
// Allow SVG upload
function my_types($mime_types)
{
$mime_types['svg'] = 'image/svg+xml'; //Adding svg extension
return $mime_types;
}
add_filter('upload_mimes', 'my_types', 1, 1);
@dksign
dksign / Automatically Protect Emails From Spambots in Wordpress Without a plugin Using WordPress antispambot() function to automatically codify all email addresses to make them harder for spambots
// Automatically Protect Emails From Spambots in Wordpress Without a plugin
function remove_plaintext_email($emailAddress) {
$emailRegEx = '/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4})/i';
// Hack because wordpress generates break after email, that get encoded together with the email
$emailAddress = str_replace('<br />', ' <br />', $emailAddress);
// END: Hack
return preg_replace_callback($emailRegEx, "encodeEmail", $emailAddress);
}
function encodeEmail($result) {
$('a[href*="#"]').on('click', function(e) {
e.preventDefault()
$('html, body').animate(
{
scrollTop: $($(this).attr('href')).offset().top,
},
500,
'linear'
)
@dksign
dksign / wp-htaccess-https
Created March 18, 2019 16:10
WP redirect http to https in .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^index\.php$ - [L]
@dksign
dksign / restart_bluetooth.sh
Created February 18, 2019 18:06 — forked from nicolasembleton/restart_bluetooth.sh
Restart Bluetooth Daemon on Mac OS X without restarting
#!/bin/bash
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
@dksign
dksign / git-log-and-diff.sh
Created November 2, 2018 17:18 — forked from jtdp/gist:5443297
See changes before pulling from remote git repository
# fetch the changes from the remote
git fetch origin
# show commit logs of changes
git log master..origin/master
# show diffs of changes
git diff master..origin/master
# apply the changes by merge..
@dksign
dksign / plugin.js
Created July 9, 2018 15:19 — forked from mburakerman/plugin.js
The simplest vanilla js plugin template
// <div id="box">Lorem</div>
// Our goal is to make text color red
var Makered = function(selector) {
this.el = document.querySelector(selector); // for multiple elements use querySelectorAll
}
Makered.prototype.makered=function() {
this.el.style.color="red";
}
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square70x70logo src="/mstile-70x70.png"/>
<square144x144logo src="/mstile-144x144.png"/>
<square150x150logo src="/mstile-150x150.png"/>
<square310x310logo src="/mstile-310x310.png"/>
<wide310x150logo src="/mstile-310x150.png"/>
<TileColor>#132935</TileColor>
@dksign
dksign / sage_favicons.php
Created July 6, 2018 12:34 — forked from schalkburger/sage_favicons.php
Roots Sage Favicons
/**
* Load favicons
* Place icons in the theme images directory. Want more? http://realfavicongenerator.net/
*/
function sage_favicons() {
echo '<link rel="apple-touch-icon" sizes="57x57" href="'. get_template_directory_uri() .'/dist/images/apple-touch-icon-57x57.png">';echo "\n";
echo '<link rel="apple-touch-icon" sizes="60x60" href="'. get_template_directory_uri() .'/dist/images/apple-touch-icon-60x60.png">';echo "\n";
echo '<link rel="apple-touch-icon" sizes="72x72" href="'. get_template_directory_uri() .'/dist/images/apple-touch-icon-72x72.png">';echo "\n";
echo '<link rel="apple-touch-icon" sizes="76x76" href="'. get_template_directory_uri() .'/dist/images/apple-touch-icon-76x76.png">';echo "\n";
echo '<link rel="apple-touch-icon" sizes="114x114" href="'. get_template_directory_uri() .'/dist/images/apple-touch-icon-114x114.png">';echo "\n";