Skip to content

Instantly share code, notes, and snippets.

Nico Martin nico-martin

Block or report user

Report or block nico-martin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nico-martin
nico-martin / nm-media-sideload.php
Last active May 19, 2019
Sideload an Image from a Post-Meta to your attachments
View nm-media-sideload.php
<?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 Aug 2, 2018
Set post as WP Front-Page
View post-as-frontpage.php
<?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 Jul 10, 2018
A WordPress Navigation Walker that adds a clean BEM CSS Structure
View class-navwalker.php
<?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
.htaccess add on for cachify flat file caching
View cachify.htaccess
# 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 Aug 2, 2018
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();
View gtag-gdpr-ready.html
<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 Feb 11, 2018
WordPress resize image on the fly
View hello_resize_image.php
/**
* @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 Nov 9, 2018
pre-commit hook that increases the version of a WP-Theme
View pre-commit
#!/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 Jun 30, 2017
A PHP Class to adjust a hex value (basicly mixing with another color)
View class-color-adjustments.php
<?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 Apr 21, 2019
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.
View WP - Google Analytics
<?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 Mar 24, 2017
A little Grid Snippet we use at sayhello.ch
View hello-grid.scss
/**
* Settings
*/
$grid-space-x : 2rem;
$grid-padding : ($grid-space-x/2);
$grid-columns : 12;
$grid-size : 1200px;
You can’t perform that action at this time.