Skip to content

Instantly share code, notes, and snippets.

View nickcernis's full-sized avatar

Nick Cernis nickcernis

  • Innsbruck, Austria
  • 16:57 (UTC +02:00)
View GitHub Profile
@nickcernis
nickcernis / functions.php
Last active May 12, 2020 12:47
Wrap Genesis titles with a link on singular posts and pages
<?php
add_filter( 'genesis_post_title_output', 'custom_wrap_singular_titles_with_links', 10, 3 );
/**
* Wrap the post title with a link on singular entries.
*
* @param string $output The original title output (title content and tags).
* @param string $wrap The title tag.
* @param string $title The content of the title tag.
* @return string The new title output.
*/
@nickcernis
nickcernis / wp-cli-snippets.md
Last active August 10, 2022 12:00
WP-CLI snippets

Delete all menus

wp menu list --format=ids | xargs wp menu delete

Delete posts of one type in bulk

wp post list --post_type='post-type-here' --format=ids | xargs wp post delete --force
@nickcernis
nickcernis / functions.php
Created February 18, 2020 19:40
Show the day in the heading on Genesis archives, even if an archive has no posts
<?php
remove_action( 'genesis_archive_title_descriptions', 'genesis_do_archive_headings_headline', 10, 3 );
add_action( 'genesis_archive_title_descriptions', 'custom_do_archive_headings_headline', 10, 3 );
/**
* Adapts archive title to display a date even for days in custom post types that have no posts.
*
* @param string $heading Optional. Archive heading, default is empty string.
* @param string $intro_text Optional. Archive intro text, default is empty string.
* @param string $context Optional. Archive context, default is empty string.
*/
@nickcernis
nickcernis / functions.php
Last active August 24, 2022 18:10
Set Genesis static homepage site title and entry title heading levels to h1 and h2
<?php
add_filter( 'genesis_entry_title_wrap', 'custom_homepage_title_to_h2' );
/**
* Set page title to h2 on a static homepage if Genesis SEO is not in use.
*
* @param string $wrap The original wrap.
* @return string The new wrap.
*/
function custom_homepage_title_to_h2( $wrap ) {
if ( is_front_page() && ! is_home() && ! genesis_seo_active() ) {
@nickcernis
nickcernis / onboarding.php
Created August 7, 2019 06:45
Importing different widgets during Genesis one-click theme setup
<?php
/**
* Genesis Sample.
*
* Onboarding config to load plugins and homepage content on theme activation.
*
* @package Genesis Sample
* @author StudioPress
* @license GPL-2.0-or-later
* @link https://www.studiopress.com/
@nickcernis
nickcernis / functions.php
Last active October 14, 2019 15:55
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.
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 October 22, 2019 22:10
Enable the block editor for Genesis Portfolio Pro
<?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 February 8, 2019 10:36
Exclude Genesis Portfolio taxonomies on the portfolio archive
<?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 February 5, 2019 18:37
Add to fish shell PATH
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 January 16, 2019 11:11
Wrap Custom HTML WordPress blocks in a div wrapper
<?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.
*/