Created
March 4, 2024 19:07
-
-
Save graylaurenm/8b3034b073b858160c44e4250deaaf96 to your computer and use it in GitHub Desktop.
Custom WPForms smart tag for WP Recipe Maker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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