Skip to content

Instantly share code, notes, and snippets.

View nico-martin's full-sized avatar
🤷‍♂️
I have no idea what I'm doing.. 90% of the time..

Nico Martin nico-martin

🤷‍♂️
I have no idea what I'm doing.. 90% of the time..
View GitHub Profile
@nico-martin
nico-martin / nm-media-sideload.php
Last active May 19, 2019 19:04
Sideload an Image from a Post-Meta to your attachments
<?php
namespace NicoMartin;
/**
* Media Sideload
* Plugin Name: NM Media Sideload
* Description: Sideload an Image from a Post-Meta to your attachments
* Version: 0.1.0
* Author: Nico Martin
@nico-martin
nico-martin / post-as-frontpage.php
Last active August 2, 2018 22:18
Set post as WP Front-Page
<?php
add_filter( 'get_pages', 'add_posts_to_frontpage_dropdown', 20, 2 );
add_action( 'pre_get_posts', 'update_frontpage_post_query' );
function add_posts_to_frontpage_dropdown( $pages, $r ) {
if ( array_key_exists( 'name', $r ) && 'page_on_front' == $r['name'] ) {
$args = [
'post_type' => 'post',
@nico-martin
nico-martin / class-navwalker.php
Last active July 10, 2018 08:45
A WordPress Navigation Walker that adds a clean BEM CSS Structure
<?php
namespace HelloTheme;
class NavWalker extends \Walker_Nav_Menu {
public $css_base = 'menu';
public function __construct( $base = '' ) {
@nico-martin
nico-martin / cachify.htaccess
Created May 29, 2018 12:20
.htaccess add on for cachify flat file caching
# BEGIN CACHIFY
<IfModule mod_rewrite.c>
# ENGINE ON
RewriteEngine on
RewriteBase /
# set hostname directory
RewriteCond %{HTTPS} on
RewriteRule .* - [E=CACHIFY_HOST:https-%{HTTP_HOST}]
RewriteCond %{HTTPS} off
@nico-martin
nico-martin / gtag-gdpr-ready.html
Last active February 24, 2020 15:28
This little snippet provides a simple way to a) implement Google Tag Manager with anonymized IP and b) provide a Opt-Out / Opt-In mechanism: gtagOptOutIn();
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X"></script>
<script>
window.gtagTrackingID = 'UA-XXXXXXXX-X';
window.gtagDisableStr = 'gtag-disable-' + gtagTrackingID;
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
@nico-martin
nico-martin / hello_resize_image.php
Last active February 11, 2018 19:54
WordPress resize image on the fly
/**
* @param $attach_id
* @param $width
* @param $height
* @param bool $crop
*
* @return false|array Returns an array (url, width, height, is_intermediate), or false, if no image is available.
*/
function hello_image_resize( $attach_id, $width, $height, $crop = false ) {
@nico-martin
nico-martin / pre-commit
Last active November 9, 2018 07:16
pre-commit hook that increases the version of a WP-Theme
#!/bin/bash
FILE=style.css
BRANCH=`git rev-parse --abbrev-ref HEAD`
# read every line and serach Version
while read line; do
if [[ $line == *"Version: "* ]]; then
VERSION=${line/Version: /}
fi
@nico-martin
nico-martin / class-color-adjustments.php
Last active June 30, 2017 07:19
A PHP Class to adjust a hex value (basicly mixing with another color)
<?php
namespace SayHello\nm;
/**
* This Class provides some color adjustments
*
* @author Nico Martin <nico@sayhello.ch>
*/
@nico-martin
nico-martin / WP - Google Analytics
Last active April 21, 2019 22:22
This is a little PHP Class that add google analytics to WordPress without lowering the Pagespeed Index. It saves analytics.js on the server and updates it daily via wp-cron.
<?php
namespace sayhello\Theme;
/**
* Get Google Analytics.js and saves it locally, inserts tracking code into wp_footer
* Advantage: No 2h googleanalytics.js cache
* +1 Google Page Speed Point
*
* @since 0.0.1
@nico-martin
nico-martin / hello-grid.scss
Last active March 24, 2017 14:48
A little Grid Snippet we use at sayhello.ch
/**
* Settings
*/
$grid-space-x : 2rem;
$grid-padding : ($grid-space-x/2);
$grid-columns : 12;
$grid-size : 1200px;