Skip to content

Instantly share code, notes, and snippets.

View nickeforsberg's full-sized avatar
💻
Focusing

Nicke Forsberg nickeforsberg

💻
Focusing
View GitHub Profile
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
@nickeforsberg
nickeforsberg / asyncSlugifier.js
Last active October 20, 2023 08:33
Child pages with parent in Sanity (Hook + page schema)
import sanityClient from 'part:@sanity/base/client';
// Slugify function from https://gist.github.com/mathewbyrne/1280286 for fixing some weird letters etc
function slugify(str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim leading/trailing white space
str = str.toLowerCase(); // convert string to lowercase
str = str.replace(/[^a-z0-9 -]/g, '') // remove any non-alphanumeric characters
.replace(/\s+/g, '-') // replace spaces with hyphens
.replace(/-+/g, '-'); // remove consecutive hyphens
return str;
@nickeforsberg
nickeforsberg / click-events.js
Created December 16, 2019 10:40
click-events.js
// How to handle click events
// jQuery
$('.button').on('click', function() { /* handle click event */});
// Vanilla
// On one button
document.querySelector('.button').addEventListener('click', (e) => { /* handle click event */});
// On multiple buttons
document.querySelectorAll('.button').forEach((button) => {
// Get elements
// jQuery
var myDivs = $('.my-div'); // Get all divs
const myDiv = document.querySelector('.myDiv'); // Get first div
const myDivs = document.querySelectorAll('.myDiv'); // Get all divs// How to handle click events
@nickeforsberg
nickeforsberg / wp_rss_feed.php
Last active June 8, 2021 09:20
Multiple Custom Post Types to Wordpress main RSS Feed.
// Add custom post types main RSS feed.
function wp_rss_feed( $query ) {
if ( $query->is_feed() )
$query->set( 'post_type', array( 'post', 'events', 'books' ) );
return $query;
}
add_filter( 'pre_get_posts', 'wp_rss_feed' );
@nickeforsberg
nickeforsberg / remove_emoji.php
Last active August 29, 2015 14:23
Get rid of emoji
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );