Skip to content

Instantly share code, notes, and snippets.

@pablo-sg-pacheco
Last active August 24, 2016 17: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 pablo-sg-pacheco/6cbe053ee61eedbe965edebfa114d0a4 to your computer and use it in GitHub Desktop.
Save pablo-sg-pacheco/6cbe053ee61eedbe965edebfa114d0a4 to your computer and use it in GitHub Desktop.
Converts content in Contact Details fields. Ex: {{email}}
<?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