Skip to content

Instantly share code, notes, and snippets.

View nickcernis's full-sized avatar

Nick Cernis nickcernis

  • Innsbruck, Austria
  • 22:17 (UTC +02:00)
View GitHub Profile
@nickcernis
nickcernis / functions.php
Last active April 23, 2019 07:21
Link Genesis post title directly to content when using the Link post format
add_filter( 'genesis_post_title_output', 'sp_link_post_format_title' );
/**
* If the post uses the “Link” post format and has a URL in the content,
* link the title directly to that URL instead of to the post itself.
*
* @param string $title_html The original title HTML.
* @return string The updated HTML.
*/
function sp_link_post_format_title( $title_html ) {
if ( get_post_format() !== 'link' ) {
@nickcernis
nickcernis / add-editor-layout-classes.js
Last active February 20, 2020 09:09
Add Genesis layout class to Gutenberg editor pages (admin)
// Add genesis layout classes to the Block Editor.
// File lives in the theme's /js/ folder.
wp.domReady(function () {
yourTheme.updateLayoutClass();
var layouts = document.querySelector(".genesis-layout-selector");
if( layouts ) {
layouts.addEventListener("input", function (e) {
yourTheme.updateLayoutClass();
@nickcernis
nickcernis / genesis.php
Created October 4, 2018 10:40
noindex paginated homepage for Genesis / Yoast
<?php
add_filter( 'genesis_get_robots_meta_content', 'sp_noindex_paginated_front_page' );
/**
* No-index paginated front-page if Genesis SEO is in use.
*
* @param array $directives The robots directives.
* @return array The directives with noindex set if on a paginated front page.
*/
function sp_noindex_paginated_front_page( $directives ) {
if ( is_front_page() && is_paged() ) {
@nickcernis
nickcernis / example.md
Created September 27, 2018 14:52
WordPress title tag filters

You can dynamically set the title tag with PHP code using the WordPress pre_get_document_title or document_title_parts filters if you're using Genesis SEO features:

add_filter( 'pre_get_document_title', 'custom_quick_title' );
function custom_quick_title() {
  return 'My custom title';
}

The document_title_parts filter gives you more fine-grained control if you just wanted to override the title or tagline, for example:

@nickcernis
nickcernis / command.sh
Created September 20, 2018 10:16
Create command line shortcut for Sublime Merge (Mac)
ln -s "/Applications/Sublime Merge.app/Contents/SharedSupport/bin/smerge" /usr/local/bin/smerge
@nickcernis
nickcernis / functions.php
Last active September 12, 2018 18:48
Adds support for editor color palette for sites using the Genesis Framework.
<?php
// Do NOT include the opening php tag.
// Adds support for editor color palette.
add_theme_support( 'editor-color-palette', array(
array(
'name' => __( 'Light gray', 'genesis-sample' ),
'slug' => 'light-gray',
'color' => '#f5f5f5',
),
@nickcernis
nickcernis / command.md
Created August 26, 2018 07:47
Delete all node_modules directories
❯ find /Path/to/parent/folder -name "node_modules" -type d -prune -exec rm -rf '{}' +
@nickcernis
nickcernis / readme.md
Last active March 7, 2024 01:43
Exclude node_modules and .git from Backblaze backups on Mac

Exclude node_modules and .git from Backblaze backups on Mac

  1. Edit the file at /Library/Backblaze.bzpkg/bzdata/bzexcluderules_editable.xml.
  2. Add these rules inside the bzexclusions tag:
<!-- Exclude node_modules. -->
<excludefname_rule plat="mac" osVers="*"  ruleIsOptional="t" skipFirstCharThenStartsWith="users/" contains_1="/node_modules/" contains_2="*" doesNotContain="*" endsWith="*" hasFileExtension="*" />
<excludefname_rule plat="mac" osVers="*"  ruleIsOptional="t" skipFirstCharThenStartsWith="users/" contains_1="/.git/" contains_2="*" doesNotContain="*" endsWith="*" hasFileExtension="*" />
@nickcernis
nickcernis / functions.php
Created July 31, 2018 17:02
Fix Google Schema error for custom logos on WordPress sites.
<?php
/**
* Fix Google Schema error, "The property logo is not recognised by Google for an object of type WPHeader".
*
* @param string $html The logo HTML.
*
* @return string The modified HTML.
*/
add_filter( 'get_custom_logo', function( $html ) {
$html = str_replace( 'itemprop="logo"', 'itemprop="image"', $html );
@nickcernis
nickcernis / wrap.sh
Last active August 26, 2018 21:38
Mac shell script: wrap clipboard contents to 70 characters and prefix as markdown blockquote, preserving links and non-ASCII
pbpaste | fmt -w 70 | sed -e 's/^/> /'