Skip to content

Instantly share code, notes, and snippets.

View mathiasmadsen's full-sized avatar

Mathias Madsen mathiasmadsen

  • Klausen og Partners
  • Copenhagen
View GitHub Profile
@adactio
adactio / saveTextarea.js
Last active December 2, 2023 06:52
Put the contents of a textarea into localStorage if the user leaves the page before submitting the form.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function (win, doc) {
// Cut the mustard.
if (!win.localStorage) return;
// You should probably use a more specific selector than this.
var textarea = doc.querySelector('textarea');
// The key for the key/value pair in localStorage is the current URL.
var key = win.location.href;
@LukaHarambasic
LukaHarambasic / functions.php
Last active August 8, 2021 10:32
Wordpress: ACF-Field as CPT Title
// inspired by: https://gist.github.com/rveitch/9018669face1686e74aaa68026856f36
// add title to CPTs which don't provide a title (useful for the relationship field (https://www.advancedcustomfields.com/resources/relationship/))
function sync_acf_post_title($post_id, $post, $update) {
$post_type = get_post_type($post_id);
// check for the current CPT
if($post_type === "cpt_name_1") {
@spigotdesign
spigotdesign / get-svg.php
Created January 25, 2016 21:29
WordPress get SVG file contents
<?php echo file_get_contents( get_stylesheet_directory_uri() . '/img/icons/your-logo-file.svg' ); ?>
@DevinWalker
DevinWalker / gist:6fb2783c05b46a2ba251
Created April 17, 2015 17:31
WordPress: Loop through Categories and Display Posts Within
<?php
/*
* Loop through Categories and Display Posts within
*/
$post_type = 'features';
// Get all the taxonomies for this post type
$taxonomies = get_object_taxonomies( array( 'post_type' => $post_type ) );
foreach( $taxonomies as $taxonomy ) :
@ludo237
ludo237 / .htaccess
Last active January 27, 2024 14:08
The ultimate .htaccess file. Please feel free to fork it, edit it and let me know what do you think about it.
# Apache configuration file
# httpd.apache.org/docs/2.2/mod/quickreference.html
# Note .htaccess files are an overhead, this logic should be in your Apache
# config if possible: httpd.apache.org/docs/2.2/howto/htaccess.html
# Techniques in here adapted from all over, including:
# Kroc Camen: camendesign.com/.htaccess
# perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/
# Sample .htaccess file of CMS MODx: modxcms.com
# This is the free sample of .htaccess from 6GO s.r.l.
# @author Claudio Ludovico Panetta (@Ludo237)
@marijn
marijn / README.markdown
Last active October 1, 2023 13:42
List of countries in YAML, CSV and TXT format