Skip to content

Instantly share code, notes, and snippets.

View onemanparsons's full-sized avatar

onemanparsons

View GitHub Profile
@onemanparsons
onemanparsons / footprint.js
Created August 27, 2020 09:27
Tooltips on SVG using Tooltipster
$(document).ready(function () {
// Only run this on Footprint page
if (top.location.pathname === "/footprint") {
$("path[data-state='active']").each( function(index) {
$(this).tooltipster({
content: function() {
var innerContent = "";
if (index == 0) {
var country = 'Zambia';
@onemanparsons
onemanparsons / .htaccess file for static HTML sites
Last active September 2, 2020 09:53
Place this .htaccess file in the root of your site. It does a couple of things: redirect http and www to https; serve site from a specific folder; and trim .html extension from URLs.
RewriteEngine On
# Redirect http:// and www. to https://
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) https://example.com/$1 [L,R=301]
# If the host is "example.com", serve site content from /dist folder
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
# Then rewrite any request to /folder
@onemanparsons
onemanparsons / WordPress simple text translations
Created November 4, 2020 10:37
Use in child theme's functions.php. Useful to translate a handful of strings. For more extensive translations a plugin like Loco Translate comes in handy.
// Theme translations
function custom_text_translate($translated) {
switch ( $translated ) {
case 'The Shop' :
$translated = 'Donate';
break;
case 'Welcome to our online store. Take some time to browse through our items.' :
$translated = 'Welcome to our donations hub.';
break;
}
@onemanparsons
onemanparsons / Create WP Admin User in PHPmyAdmin
Created November 11, 2020 08:54
Use this SQL query to add a new admin user via PHPmyAdmin
INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('4', 'demo', MD5('demo'), 'Your Name', 'test@yourdomain.com', 'http://www.test.com/', '2011-06-07 00:00:00', '', '0', 'Your Name');
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_user_level', '10');
@onemanparsons
onemanparsons / Run script based on UTM parameters
Created May 14, 2021 15:04
Get UTM parameter values and run script
// Get all URL parameters
function getUrlParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
@onemanparsons
onemanparsons / .htaccess to redirect http to https
Last active May 21, 2021 12:07
Redirect http to https using .htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@onemanparsons
onemanparsons / Update WC FlexSlider options
Created December 3, 2021 07:40
Customise the behaviour of WooCommerce slider on single-product
// Make Update WooCommerce Flexslider options
add_filter( 'woocommerce_single_product_carousel_options', 'ud_update_woo_flexslider_options' );
function ud_update_woo_flexslider_options( $options ) {
$options['directionNav'] = true;
$options['animation'] = "slide";
$options['animationLoop'] = true;
$options['slideshow'] = true;