Skip to content

Instantly share code, notes, and snippets.

@robincornett
robincornett / gravity-save-continue-two-users.php
Created December 30, 2019 16:56
Set up a Gravity Form (in this case, form ID 1) to be sent from one user to another, by repurposing the "save and continue" button.
<?php
add_filter( 'gform_savecontinue_link_1', 'prefix_savecontinue_form_id_1', 10, 2 );
/**
* Maybe remove the "save and continue" button from Gravity Form ID 1.
* Checks to see if the "save and continue" token is present--
* if no, the button will render, otherwise not.
*
* @param string $save_button
* @param object $form
@robincornett
robincornett / functions.php
Created October 16, 2019 12:57
Add the editor color palette to your site using wp_inline_style
<?php
add_action( 'enqueue_block_assets', 'rgc_editor_color_palette', 15 );
/**
* Add custom colors to the site using wp_inline_style, attached to the wp-block-library stylesheet.
* Colors must be defined in your theme or functionality plugin.
*/
function rgc_editor_color_palette() {
list( $colors, ) = (array) get_theme_support( 'editor-color-palette' );
if ( ! $colors ) {
@robincornett
robincornett / functions.php
Created October 14, 2019 20:24
Add custom editor font sizes to your site after the block library styles using wp_inline_style.
<?php
add_action( 'enqueue_block_assets', 'rgc_editor_font_sizes', 15 );
/**
* Add custom font sizes to the site using wp_inline_style, attached to the wp-block-library stylesheet.
* Editor font sizes must be defined in your theme.
*/
function rgc_editor_font_sizes() {
list( $font_sizes, ) = (array) get_theme_support( 'editor-font-sizes' );
if ( ! $font_sizes ) {
@robincornett
robincornett / functions.php
Created September 11, 2019 16:31
Sample code to add the Print Friendly service as a scriptless sharing button
<?php
add_filter( 'scriptlesssocialsharing_networks', 'rgc_scriptless_networks' );
/**
* Add Print Friendly to settings/allowed sharing buttons
*
* @param $networks
*
* @return mixed
*/
@robincornett
robincornett / functions.php
Created August 27, 2019 18:56
Sample function to change the banner featured image output in Display Featured Image for Genesis to a slideshow. This example is not applied conditionally, so would change the output sitewide. It starts with four image IDs and adds them to the slider output as URLs (required).
<?php
add_filter( 'display_featured_image_genesis_backstretch_variables', 'rgc_test_slider_filter' );
/**
* Change the banner featured image to be a slidehow sitewide.
*
* @param array $variables
* @return array
*/
function rgc_test_slider_filter( $variables ) {
@robincornett
robincornett / comments-remove-date.php
Last active August 21, 2019 14:55
Update Genesis comments to include only the date, not the time, the comment was posted.
<?php
// Completely remove the date and time from comments.
add_filter( 'genesis_show_comment_date', '__return_false' );
@robincornett
robincornett / twitter-modification.php
Created April 23, 2019 20:06
Add a hashtag to all Twitter sharing buttons on a site (in Scriptless 3.0.0)
<?php
add_filter( 'scriptlesssocialsharing_twitter_query_args', 'prefix_add_twitter_hashtag_scriptless' );
/**
* Add a hashtag to every Twitter button on a site.
* Requires Scriptless Social Sharing 3.0.0
*
* @param $query_args
* @return mixed
*/
@robincornett
robincornett / functions.php
Created March 4, 2019 22:58
Use Simple Social Icons' SVG in Scriptless Social Sharing. Note: unless you are enqueueing the SSI CSS/JS independently, these will only work on pages where an instance of the SSI widget is being output.
<?php
add_filter( 'scriptlesssocialsharing_link_markup', 'prefix_modify_scriptless_link_markup', 10, 2 );
/**
* Add SVG icons to Scriptless sharing buttons.
*
* @param $output
*
* @param $button
*
@robincornett
robincornett / functions.php
Created January 30, 2019 20:31
Sample code to add Facebook Messenger as a sharing button to Scriptless Social Sharing.
<?php
add_filter( 'kses_allowed_protocols', 'prefix_allow_messenger' );
/**
* Add Facebook Messenger to the list of allowed URL protocols in WordPress.
*
* @param $protocols
*
* @return array
*/
@robincornett
robincornett / pocket.php
Last active December 17, 2018 13:53
Add a button for Pocket to Scriptless Social Sharing.
<?php
add_filter( 'scriptlesssocialsharing_pocket_url', 'prefix_add_pocket', 10, 3 );
/**
* Create the URL for the Pocket share/save button.
*
* @param $url
* @param $button
* @param $attributes
*