SHOW:
|
|
- or go back to the newest paste.
1 | - | /* If you code a page template directly, you can add the function like so: */ |
1 | + | // Coding directly into a page template, you can use the built-in WordPress function below: |
2 | antispambot( "youremail@yoursite.com" ); | |
3 | - | antispambot("youremail@yoursite.com"); |
3 | + | |
4 | // A way to make use of the antispambot() function within posts and pages content using a shortcode | |
5 | - | /* A way to take advantage of the antispambot() function within posts and pages content */ |
5 | + | // EMAIL ENCODE SHORTCODE |
6 | - | // EMAIL ENCODE SHORTCODE |
6 | + | function encode_email_shortcode( $atts, $address = null ){ |
7 | - | function email_encode_function( $atts, $content ){ |
7 | + | if( !is_email( $address ) ){ |
8 | - | return '<a href="'.antispambot("mailto:".$content).'">'.antispambot($content).'</a>'; |
8 | + | return; |
9 | } | |
10 | - | add_shortcode( 'email', 'email_encode_function' ); |
10 | + | $mailtoaddr = antispambot( $address ); |
11 | $maillink = '<a href="mailto:'; | |
12 | - | /* Code snippet goes in function.php file. |
12 | + | $maillink .= $mailtoaddr; |
13 | - | Use the following structure to safely display an email address in your post or page content: |
13 | + | $maillink .= ( isset( $atts['subject'] ) ? '?subject='.$atts['subject'] : '' ); |
14 | $maillink .= '" target="_blank">'; | |
15 | $maillink .= ( isset( $atts['output'] ) ? $atts['output'] : $mailtoaddr ); | |
16 | $maillink .= '</a>'; | |
17 | return $maillink; | |
18 | } | |
19 | add_shortcode( 'email', 'encode_email_shortcode' ); | |
20 | ||
21 | /* | |
22 | Code snippet above goes in your theme function.php | |
23 | Use the following structure to safely display an email address in your post or page content: | |
24 | ||
25 | [email]you@you.com[/email] | |
26 | [email subject="Website Inquiry"]you@you.com[/email] | |
27 | [email output="Click here to contact us"]you@you.com[/email] | |
28 | [email output="Click here to contact us" subject="Website Inquiry"]you@you.com[/email] | |
29 | ||
30 | */ |