Skip to content

Instantly share code, notes, and snippets.

@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 / rss-email.txt
Created May 31, 2014 18:30
MailChimp RSS email template
*|RSSITEMS:|*
<h2 class="mc-toc-title"><a href="*|RSSITEM:URL|*" target="_blank">*|RSSITEM:TITLE|*</a></h2>
*|RSSITEM:CONTENT_FULL|*<br />
<a href="*|RSSITEM:URL|*" target="_blank">Read in browser &raquo;</a><br />
*|RSSITEM:TWITTER|* *|RSSITEM:LIKE|*<br />
<br />
*|END:RSSITEMS|*
@robincornett
robincornett / functions.php
Last active April 12, 2022 07:36
optional home.php--to show the posts (blog) page's title and content
<?php
// do NOT include the opening line! Just add what's below to the end of your functions.php file
add_action( 'edit_form_after_title', 'rgc_posts_page_edit_form' );
function rgc_posts_page_edit_form( $post ) {
$posts_page = (int) get_option( 'page_for_posts' );
if ( $posts_page === $post->ID ) {
add_post_type_support( 'page', 'editor' );
}
@robincornett
robincornett / photon.php
Last active February 21, 2022 17:12
Disable the Jetpack Photon module so that you can work with WordPress' image functions
<?php
// do not include the opening php tag
// turn Photon off so we can get the correct image
$photon_removed = '';
if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) { // check that we are, in fact, using Photon in the first place
$photon_removed = remove_filter( 'image_downsize', array( Jetpack_Photon::instance(), 'filter_image_downsize' ) );
}
@robincornett
robincornett / plugin.php
Created November 10, 2017 18:52
Code snippet to add a custom plugin icon to the WordPress plugins update page. Icons were added to this page in WordPress 4.9 and are automatically shown for plugins hosted in the WordPress repository, but not for plugins hosted/updated elsewhere.
<?php
add_filter( 'all_plugins', 'prefix_add_plugin_icon' );
/**
* Add a custom plugin icon to the plugins update page (introduced in WP4.9).
*
* @param $plugins
*
* @return mixed
*/
@robincornett
robincornett / navigation.php
Created July 13, 2014 20:20
updated Walker_Nav_Menu_Dropdown class for strict standards
<?php
/**
* source: http://www.billerickson.net/code/wordpress-menu-as-select-dropdown/
* Use this class to set up a nav menu to use as a dropdown menu.
*/
class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{
function start_lvl( &$output, $depth = 0, $args = array() ){
@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 / 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 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
*/