Skip to content

Instantly share code, notes, and snippets.

View jonbrockett's full-sized avatar

Jon Brockett jonbrockett

View GitHub Profile
// Hero Video
.hero-video {
left: 50%; // To center video
transform: translate(-50%, 0); // To center video
min-width: 100%; // To stretch to the container
min-height: 100%; // To stretch to the container
position: absolute;
z-index: -1; // To drop behind content
}
@jonbrockett
jonbrockett / functions.php
Created January 17, 2019 14:36
Get Posts (Blog) Page Title (Custom WP Function)
/** The Posts (Blog) Page Title */
require_once( 'library/get-posts-page-title.php' );
@jonbrockett
jonbrockett / functions.php
Created January 17, 2019 14:35
Get Top Parent Page (Custom WP Function)
/** Current Page's Parent */
require_once( 'library/get_top_parent.php' );
@jonbrockett
jonbrockett / _buttons.scss
Created January 17, 2019 14:31
White Button (Foundation SCSS Class)
// White Button
.button.white {
background-color: $white;
color: $black;
border-color: $black;
&:hover {
background-color: scale-color($white, $lightness: -15%);
border-color: scale-color($black, $lightness: 15%);
color: scale-color($black, $lightness: 15%);
@jonbrockett
jonbrockett / format-phone.php
Created January 17, 2019 14:31
Format Phone Number (Custom Function)
<?php
/**
* Format Phone Number
*
* This function takes a 10 digit phone number and formats it
*/
function format_phone($s) {
$rx = "/
(1)?\D* # optional country code
@jonbrockett
jonbrockett / functions.php
Created January 17, 2019 14:28
String to Slug
/** Convert string to slug */
require_once( 'library/string-to-slug.php' );
@jonbrockett
jonbrockett / Readme.md
Created January 17, 2019 14:27
WP - Adjust Media Library Thumbnail Sizes

You will generally want to use this when adjusting the medium and large size in the WP settings. Otherwise a much larger image will be used, bogging down the media library load.

Also, if you unset the medium file size, the full image size will be used. All the more important to use it for that.

To use in the FoundationPress theme, add before you register the new image sizes for use in the add media modal in wp-admin.

Or more generically, add to the functions.php file.

@jonbrockett
jonbrockett / Readme.md
Created January 17, 2019 14:26
WP - Reorganize Media Library Image Order

This is important when adding custom image sizes. The FoundationPress theme add new sizes by default. What happens is when you add new images sizes they go at the end of the list, so it would be, "Thumbnail, Medium, Large, Full Size, Small, XLarge". This is confusing to the user and will auto select medium normally. The best order is to have the image sizes in order from smallest to largest, then full size, then the thumbnail.

The important piece is after the comment "Unset WP Default sizes so they can be reordered with new custom sizes". This removes them from the list of available image sizes. Then right after you re-add them in order as well as custom sizes.

FoundationPress theme you can edit to add the "unset" rules then add them into the $sizes array. More generically, you can add this to functions.php.

@jonbrockett
jonbrockett / rest-api-existing-cpt.php
Created January 17, 2019 14:25
WP REST API on Existing Custom Post Types
<?php
/**
* Add REST API to an existing custom post type
* Remember to add existing custom fields
*/
function add_cpts_to_api( $args, $post_type ) {
if ( 'post_name' === $post_type ) {
$args['show_in_rest'] = true;
}
@jonbrockett
jonbrockett / gravity-forms-enforce-honeypot.php
Created January 17, 2019 14:25
Gravity Forms Enforce Honeypot
<?php
add_filter( 'gform_form_post_get_meta', __NAMESPACE__ . '\\enforce_gravity_forms_anti_spam_honeypot' );
/**
* Enforce anti-spam honeypot on all Gravity forms.
*
* @param array $form The current form to be filtered.
*
* @return array
*/
function enforce_gravity_forms_anti_spam_honeypot( $form ): array {