Last active
August 24, 2016 17:07
-
-
Save pablo-sg-pacheco/6cbe053ee61eedbe965edebfa114d0a4 to your computer and use it in GitHub Desktop.
Converts content in Contact Details fields. Ex: {{email}}
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 | |
//Converts content in Contact Details fields. Ex: {{email}} | |
add_filter( 'the_content', function($content){ | |
$contactDetails = get_option('contact'); | |
foreach ( $contactDetails as $key => $detail ) { | |
if ( !empty($detail) ) { | |
if(strpos($detail, '@')!==false){ | |
$content = str_replace('{{'.$key.'}}', '<a href="mailto:' . $detail . '">' . $detail . '</a>', $content); | |
}else if(strpos($detail, 'http://')!==false){ | |
$content = str_replace('{{'.$key.'}}', '<a target="_blank" href="' . $detail . '">' . $detail . '</a>', $content); | |
}else{ | |
$content = str_replace('{{'.$key.'}}', $detail, $content); | |
} | |
} | |
} | |
return $content; | |
}); | |
add_filter('contact_details', function( $details ) { | |
foreach ($details as $key => $detail) { | |
$details[$key]['label'].=' - {{'.$key.'}}'; | |
} | |
return $details; | |
}); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment