Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick Cernis nickcernis

  • Innsbruck, Austria
View GitHub Profile
@nickcernis
nickcernis / functions.php
Last active Oct 14, 2019
Prevent 'NotAllowedError' and 'user didn't interact with the document first' errors for Vimeo embedded in WordPress. No longer needed in WP 5.3 beta 3 or higher.
View functions.php
add_action( 'wp_enqueue_scripts', 'studiopress_load_newer_vimeo_mediaelement', 100 );
/**
* Replace the mediaelement-vimeo script with a newer version.
*
* This works around an issue in WordPress core that can prevent playback of
* Vimeo videos embedded via the `wp_video_shortcode()` function.
*
* This is caused by WordPress loading an older version of the Vimeo script
* (currently loads 4.2.6), which does not add the 'allow=autoplay'
* attribute to iframes that Chrome now requires to permit video playback as
@nickcernis
nickcernis / genesis-portfolio-pro-modifications.php
Last active Oct 22, 2019
Enable the block editor for Genesis Portfolio Pro
View genesis-portfolio-pro-modifications.php
<?php
/*
Plugin Name: Genesis Portfolio Pro Modifications
Description: Enable the Block Editor for the Portfolio post type.
Version: 1.0.0
*/
add_filter( 'register_post_type_args', 'studiopress_enable_block_editor_portfolio', 10, 2 );
function studiopress_enable_block_editor_portfolio( $args, $post_type ) {
@nickcernis
nickcernis / functions.php
Created Feb 8, 2019
Exclude Genesis Portfolio taxonomies on the portfolio archive
View functions.php
<?php // omit this line from functions.php
add_filter( 'pre_get_posts', 'custom_remove_portfolio_taxonomy' );
function custom_remove_portfolio_taxonomy( $query ) {
if ( is_post_type_archive( 'portfolio' ) && $query->is_main_query() ) {
$tax_query = array(
array(
'taxonomy' => 'portfolio-type',
'field' => 'slug',
'terms' => array( 'type1', 'type2' ), // Change this to use the portfolio taxonomies you want to exclude.
@nickcernis
nickcernis / fish_path.txt
Created Feb 5, 2019
Add to fish shell PATH
View fish_path.txt
set fish_user_paths $fish_user_paths my_path
From https://github.com/fish-shell/fish-shell/issues/527#issuecomment-32237807.
@nickcernis
nickcernis / functions.php
Created Jan 16, 2019
Wrap Custom HTML WordPress blocks in a div wrapper
View functions.php
<?php
add_filter( 'render_block', 'custom_wrap_html_block_output', 10, 2 );
/**
* Wrap output of HTML blocks.
*
* @param string $block_content Original block content.
* @param array $block Block info.
* @return string The block content with a wrapper.
*/
@nickcernis
nickcernis / functions.php
Last active Apr 23, 2019
Link Genesis post title directly to content when using the Link post format
View functions.php
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 Feb 20, 2020
Add Genesis layout class to Gutenberg editor pages (admin)
View add-editor-layout-classes.js
// 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 Oct 4, 2018
noindex paginated homepage for Genesis / Yoast
View genesis.php
<?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 Sep 27, 2018
WordPress title tag filters
View example.md

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 Sep 20, 2018
Create command line shortcut for Sublime Merge (Mac)
View command.sh
ln -s "/Applications/Sublime Merge.app/Contents/SharedSupport/bin/smerge" /usr/local/bin/smerge