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 / InnerBlock-renderAppender-block.jsx
Last active Jul 9, 2019
Gutenberg InnerBlock with renderAppender
View InnerBlock-renderAppender-block.jsx
const {TextControl, IconButton} = wp.components;
const {InnerBlocks} = wp.editor;
const {__} = wp.i18n;
const {dispatch} =;
const {createBlock, registerBlockType} = wp.blocks;
registerBlockType('prefix/container', {
title: 'Container',
icon: 'category',
category: 'category',
nico-martin / block-ssr.js
Last active Jun 26, 2019
This is an example of a server side rendered block without any build step. It's all plain JS/PHP and it uses the helpers and components WordPress already offers in the block admin interface.
View block-ssr.js
(function (blocks, components, element) {
blocks.registerBlockType('test/ssr', {
title: 'Server Side Rendered Block',
icon: 'admin-site-alt3',
category: 'test',
edit: function (props) {
return element.createElement(components.ServerSideRender, {block: 'test/ssr'});
save: function () {
return null;
nico-martin / ServerSideRender.jsx
Last active Jun 26, 2019
ServerSideRender block
View ServerSideRender.jsx
const {ServerSideRender} = wp.components;
wp.blocks.registerBlockType('test/ssr', {
title: 'Post Archiv',
icon: 'grid-view',
category: 'my-category',
edit(props) {
return <ServerSideRender block="test/ssr"/>
save() {
nico-martin / .htaccess
Last active Jun 13, 2019
Cache-Control headers
View .htaccess
<ifModule mod_headers.c>
# One year for image and video files
<filesMatch ".(flv|gif|ico|jpg|jpeg|mp4|mpeg|png|svg|swf|webp)$">
Header set Cache-Control "max-age=31536000, public"
# One month for JavaScript and PDF files
<filesMatch ".(js|pdf)$">
Header set Cache-Control "max-age=2592000, public"
View loadfonts.js
function loadFont(t, e, n) {
return new Promise(resolve => {
const a = navigator.userAgent;
if (window.addEventListener && (!a.match(/(Android (2|3|4.0|4.1|4.2|4.3))|(Opera (Mini|Mobi))/) || a.match(/Chrome/))) {
let o = {};
try {
o = localStorage || {}
} catch (t) {}
const r = t, i = r + "url", s = r + "css", d = o[i], c = o[s], l = document.createElement("style");
if (l.rel = "stylesheet", document.head.appendChild(l), !c || d !== e && d !== n) {
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
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 / 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
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 / pre-commit
Last active Nov 9, 2018
pre-commit hook that increases the version of a WP-Theme
View pre-commit
BRANCH=`git rev-parse --abbrev-ref HEAD`
# read every line and serach Version
while read line; do
if [[ $line == *"Version: "* ]]; then
VERSION=${line/Version: /}
nico-martin / post-as-frontpage.php
Last active Aug 2, 2018
Set post as WP Front-Page
View post-as-frontpage.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 / 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=""></script>
window.gtagTrackingID = 'UA-XXXXXXXX-X';
window.gtagDisableStr = 'gtag-disable-' + gtagTrackingID;
window.dataLayer = window.dataLayer || [];
function gtag() {
You can’t perform that action at this time.