Skip to content

Instantly share code, notes, and snippets.

@graylaurenm
Created March 4, 2024 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graylaurenm/8b3034b073b858160c44e4250deaaf96 to your computer and use it in GitHub Desktop.
Save graylaurenm/8b3034b073b858160c44e4250deaaf96 to your computer and use it in GitHub Desktop.
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;
}
/**
* Process the Smart Tag.
*/
add_filter( 'wpforms_smart_tag_process', 'oc_process_smarttag', 10, 2 );
function oc_process_smarttag( $content, $tag ) {
if ( 'recipe' === $tag ) {
$post_id = get_the_ID();
$link = do_shortcode( '[wprm-recipe-name tag="h2" text_style="normal"]' ) . '<br>' . do_shortcode( '[wprm-recipe-ingredients header="Ingredients"]' ) . do_shortcode( '[wprm-recipe-instructions header="Instructions" image_size="medium"]' );
$content = str_replace( '{recipe}', $link, $content );
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment