Last active
December 14, 2015 21:51
-
-
Save glueckpress/4421330 to your computer and use it in GitHub Desktop.
[WordPress] Concise shortcode function for an anti-spambotted email link in WordPress. Parameters for class, style (check for support in your wysiwyg editor!) and title attributes. Parameters before, after, before_text and after_text for most concise control of the final HTML output.
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 | |
/** | |
* WordPress shortcode for e-mail link | |
* [email_link address="user@domain.tld" text="E-Mail me!"] | |
* | |
* @param address (required) E-Mail address | |
* @param text (required) Link text | |
* @param before (optional) HTML to go before the <a> tag | |
* @param after (optional) HTML to go after the </a> tag | |
* @param before_text (optional) HTML to go before the link text | |
* @param after_text (optional) HTML to go after the link text | |
* @param class (optional) class attribute for <a> | |
* @param style (optional) style attribute for <a> | |
* @param title (optional) title attribute for <a> | |
* | |
* @return HTML <a> tag with specified e-mail address, text and attributes | |
*/ | |
add_shortcode( 'email_link', 'gp121231_shortcode_mailto' ); | |
function gp121231_shortcode_mailto( $atts ) { | |
extract( shortcode_atts( | |
array( | |
'address' => 'mailto:enter@address.please' | |
,'text' => '--Please enter a link text!--' | |
,'after' => '' | |
,'before' => '' | |
,'after_text' => '' | |
,'before_text' => '' | |
,'class' => '' | |
,'rel' => '' | |
,'style' => '' | |
,'title' => '' | |
), | |
$atts) ); | |
$address = antispambot( $address ); | |
$text = antispambot( $text ); | |
$class = $class ? ' class="' . $class . '"' : ''; | |
$title = $title ? ' title="' . $title . '"' : ''; | |
$rel = $rel ? ' rel="' . $rel . '"' : ''; | |
$style = $style ? ' style="' . $style . '"' : ''; | |
$output = $before . '<a href="mailto:'; | |
$output .= $address . '"'; | |
$output .= $class . $title . $style . '>'; | |
$output .= $before_text . $text . $after_text; | |
$output .= '</a>' . $after; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment