Created
June 30, 2022 17:18
-
-
Save woodwardtw/38dcfa35f194e1b592ff134fe6b7925e to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
//simple GF merge field modifier that replaces the space with a dash | |
add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifier, $field, $raw_value, $format ) { | |
if ( $merge_tag != 'all_fields' && $modifier == 'urlmaker' ) { | |
$value = str_replace(" ", "-", $value); | |
} | |
return $value; | |
}, 10, 6 ); | |
//more complex GF merge field modifier that deals with mulitple entries | |
add_filter( 'gform_merge_tag_filter', 'bava_modifier', 10, 6 ); | |
function bava_modifier ( $value, $merge_tag, $modifier, $field, $raw_value, $format ) { | |
$html = ''; | |
if ( $merge_tag != 'all_fields' && $modifier == 'bavait' ) { | |
$array_it = explode(', ',$value); | |
foreach ($array_it as $item) { | |
$hyphen = str_replace(" ", "-", $item); | |
$url = site_url(); | |
$html .= "<a class='bava-link' href='{$url}/tag/{$hyphen}'>{$item}</a><br>"; | |
} | |
$value = $html; | |
} | |
return $value; | |
} | |
//as shortcode that doesn't care about gf at all, it just shows the post's tags | |
function bava_tags(){ | |
$post_tags = get_the_tags(); | |
$html = ''; | |
if ( ! empty( $post_tags ) ) { | |
foreach ( $post_tags as $tag ) { | |
$html .= '<a href="' . esc_attr( get_tag_link( $tag->term_id ) ) . '">' . __( $tag->name ) . '</a><br>'; | |
} | |
} | |
return trim( $html ); | |
} | |
add_shortcode('bava-tags', 'bava_tags'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment