Skip to content

Instantly share code, notes, and snippets.

View lori's full-sized avatar

Lori Berkowitz lori

View GitHub Profile
@djrmom
djrmom / custom-hooks.php
Created June 20, 2018 15:06
facetwp move spaces to right
<?php
/** moves non-breaking spaces to right of fselect label **/
add_filter( 'facetwp_facet_html', function( $output, $params ) {
if ( 'my_facet_name' == $params['facet']['name'] ) { // replace 'my_facet_name' with name of your facet
$pattern = '/>([&nbsp;]+)([^<]+)/';
$output = preg_replace( $pattern, '>${2} ${1}', $output );
}
return $output;
}, 10, 2 );
@srikat
srikat / class-custom-featured-post.php
Last active April 3, 2022 16:29 — forked from GaryJones/readme.md
Custom Featured Posts Widget plugin: Skeleton for amending the output of the Genesis Featured Posts widget. https://sridharkatakam.com/custom-featured-post-widget-plugin/
<?php
/**
* Plugin Name
*
* @package Custom_Featured_Post_Widget
* @author Gary Jones
* @license GPL-2.0+
* @link http://gamajo.com/
* @copyright 2013 Gary Jones, Gamajo Tech
*/
<?php
function mrp_posts_fields( $posts_fields ) {
if ( is_main_query() ) {
$sticky_posts = get_option( 'sticky_posts' );
if ( is_array( $sticky_posts ) && ! empty( $sticky_posts ) ) {
$sticky_posts = implode( ', ', $sticky_posts );
/**
* Template Redirect
* Use page_beaver.php for all static Pages.
*/
add_filter( 'template_include', 'custom_page_template', 99 );
function custom_page_template( $template ) {
if ( is_singular( 'page' ) ) {
$new_template = locate_template( array( 'page_beaver.php' ) );
if ( '' != $new_template ) {
@tomazzaman
tomazzaman / class-developer-import.php
Created March 31, 2015 18:03
Import JSON into WordPress
<?php
// Published under GPL
// tutorial here: https://codeable.io/community/how-to-import-json-into-wordpress/
class Developer_Import {
public function __construct() {
add_action( 'wp_ajax_import_developer', array( $this, 'import_developer' ) );
@jchristopher
jchristopher / gist:046e62499a9f32cc8b7b
Last active June 21, 2020 23:23
Have SearchWP short circuit if an empty search was submitted
<?php
if ( isset( $_GET['s'] ) && 0 == strlen( trim( $_GET['s'] ) ) ) {
add_filter( 'searchwp_short_circuit', '__return_true' );
}
@spivurno
spivurno / gw-gravity-forms-edit-entries.php
Last active December 19, 2021 01:01
Gravity Wiz // Gravity Forms // Edit Entries on Frontend — https://gravitywiz.com/edit-gravity-forms-entries-on-the-front-end/
<?php
/**
* --------------------------------------------------------------------
* STOP! There's a better way to do this now:
* https://gravitywiz.com/edit-gravity-forms-entries-on-the-front-end/
* --------------------------------------------------------------------
*
* Gravity Wiz // Gravity Forms // Edit Entries
*
* Automatically populate a form with data based on an entry ID and update that entry on submission.
@calliaweb
calliaweb / display-advanced-custom-fields-gallery-as-an-envira-gallery.php
Last active November 11, 2020 18:44
Display Advanced Custom Fields Gallery as an Envira Gallery
@chriscoyier
chriscoyier / frontendplugins.md
Last active March 3, 2021 17:31
How WordPress Plugins Should Handle Front End Resources

How WordPress Plugins Should Handle Front End Resources

This is a WORK IN PROGRESS intended for fleshing out and feedback

It's very common for people to be unhappy with how a WordPress plugin adds front end resources to their site. If a plugin needs CSS, the plugin will add a <link> element to that CSS. If the plugin needs JavaScript, it will add a <script> to that JavaScript.

Plugins do this because it works. It's damn important for a WordPress plugin to work, even in adverse conditions. They rightfully want good ratings and little customer support.

But this comes at the cost of additional HTTP requests. In optimizing front end performance of a site, reducing the number of HTTP requests is a huge thing. Front end developers want to decide and control how front end resources are being handled, and WordPress plugins don't typically make this easy on them.

@imknight
imknight / gravity-form-save-acf
Last active November 22, 2017 21:29
WordPress Gravity Form Save Custom Meta Field for Advanced Custom Fields
add_action("gform_after_submission_1", "acf_post_submission", 10, 2);
function acf_post_submission ($entry, $form)
{
$post_id = $entry["post_id"];
update_field('address1', $entry['29.1'], $post_id);
update_field('address2', $entry['29.2'], $post_id);
update_field('address3', $entry['29.3'], $post_id);
}