Skip to content

Instantly share code, notes, and snippets.

View graylaurenm's full-sized avatar

Lauren Gray graylaurenm

View GitHub Profile
@graylaurenm
graylaurenm / find.txt
Last active April 25, 2024 19:03
WPRM: convert fallback HTML (when migrating from Tasty Recipes) to block
/(<!--WPRM Recipe (\d+)-->.*<!--End WPRM Recipe-->)(?!.*<!-- \/wp:wp-recipe-maker\/recipe -->)/s
@graylaurenm
graylaurenm / block.html
Created March 5, 2024 14:40
Starter block for recipe post save for later
<!-- wp:group {"style":{"color":{"background":"#f4f4f4"},"spacing":{"padding":{"top":"2rem","bottom":"2rem","left":"2rem","right":"2rem"}}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group has-background" style="background-color:#f4f4f4;padding-top:2rem;padding-right:2rem;padding-bottom:2rem;padding-left:2rem"><!-- wp:heading -->
<h2 class="wp-block-heading">Email me this recipe</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Thinking about making this recipe? Save it for later by emailing yourself a copy.</p>
<!-- /wp:paragraph -->
<!-- wp:group {"backgroundColor":"base-2","layout":{"type":"flex","flexWrap":"nowrap","orientation":"horizontal","justifyContent":"space-between"}} -->
@graylaurenm
graylaurenm / snippet.php
Created March 4, 2024 19:07
Custom WPForms smart tag for WP Recipe Maker
/**
* Register the Smart Tag so it will be available to select in the form builder.
*
*/
add_filter( 'wpforms_smart_tags', 'oc_register_smarttag', 10, 1 );
function oc_register_smarttag( $tags ) {
$tags[ 'recipe' ] = 'Recipe';
return $tags;
<?php
add_filter( 'tasty_recipes_recipe_template_vars', __NAMESPACE__ . '\replace_tasty_image_size', 10, 2 );
function replace_tasty_image_size( $template_vars, $recipe ) {
$recipe_json = $recipe->to_json();
$template_vars['recipe_image'] = ! empty( $recipe_json['image_sizes']['placement-recipe'] ) ? $recipe_json['image_sizes']['placement-recipe']['html'] : '';
return $template_vars;
}
@graylaurenm
graylaurenm / block-column.css
Last active September 3, 2018 15:11
Gutenberg
/* Support column layouts. */
.wp-block-columns .wp-block-column {
margin-left: 12px;
}
.has-2-columns .wp-block-column:nth-of-type(2n+1),
.has-3-columns .wp-block-column:nth-of-type(3n+1),
.has-4-columns .wp-block-column:nth-of-type(4n+1),
.has-5-columns .wp-block-column:nth-of-type(5n+1),
.has-6-columns .wp-block-column:nth-of-type(6n+1) {
@graylaurenm
graylaurenm / srcset.php
Created February 26, 2018 18:21
Cool things we can do with srcset in themes...
<?php
/**
* When using thumbnails, anything using the chosen
* thumbnail size should adjust their srcset sizes to
* match. This assumes image sizes are always precise and
* used in the same layouts/collapse.
*
* In this case, the chosen image is 222px wide on larger
* screens and about 29-31% of the viewport on smaller.
@graylaurenm
graylaurenm / .htaccess
Last active November 4, 2017 13:10
Redirect to HTTPS
# @see https://really-simple-ssl.com/knowledge-base/manually-insert-htaccess-redirect-http-to-https/
# BEGIN Redirect to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# END Redirect to HTTPS
@graylaurenm
graylaurenm / functions.php
Created September 27, 2017 20:43
Force posts to update (make no changes)
<?php // Do not include this line
add_action( 'init', 'oc_force_post_update' );
function oc_force_post_update() {
$my_posts = get_posts(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 10,
'offset' => 0,
@graylaurenm
graylaurenm / functions.php
Last active March 15, 2017 23:19
Add affiliate disclosure to top of posts
<?php // do not include this line
add_action( 'genesis_entry_content', 'oc_snippet_do_disclosure', 1 );
function oc_snippet_do_disclosure() {
if ( is_singular( 'post' ) ) {
echo '<p><strong>Disclosure: </strong>This post may contain affiliate links. I receive a small commission at no cost to you when you make a purchase using my link.</p>';
}
}
@graylaurenm
graylaurenm / mpp-wprm-servings-fix.php
Last active January 8, 2017 17:01
MPP to WPRM "Servings" Fix
<?php
$recipes = WPRM_Recipe_Manager::get_recipes();
foreach ( $recipes as $recipe_id => $options ) {
$recipe = WPRM_Recipe_Manager::get_recipe( $recipe_id );
if ( ! $recipe->servings() ) {
$import_source = get_post_meta( $recipe_id, 'wprm_import_source', true );