Sorry but I get lost on Wordpress's codex. I am trying to add a mail this page sharing link and want to include some info from the page. In pseudo code is this possible?
<a href="mailto:?subject=".CURRENT_BLOG_NAME." ".CURRENT_PAGE_TITLE."&body="intro%20text%20".WP_PLUGIN_URL.$_SERVER['REQUEST_URI'].">Mail to a friend</a>
Where CURRENT_BLOG_NAME
is ???
and CURRENT_PAGE_TITLE
is ???
WP_PLUGIN_URL.$_SERVER['REQUEST_URI']
does get me the path to the current page.
Sorry but I get lost on Wordpress's codex. I am trying to add a mail this page sharing link and want to include some info from the page. In pseudo code is this possible?
<a href="mailto:?subject=".CURRENT_BLOG_NAME." ".CURRENT_PAGE_TITLE."&body="intro%20text%20".WP_PLUGIN_URL.$_SERVER['REQUEST_URI'].">Mail to a friend</a>
Where CURRENT_BLOG_NAME
is ???
and CURRENT_PAGE_TITLE
is ???
WP_PLUGIN_URL.$_SERVER['REQUEST_URI']
does get me the path to the current page.
2 Answers
Reset to default 1<?php
$link = 'mailto:?subject='. get_bloginfo() .' '. the_title_attribute(array('echo'=>0));
$link .= '&body=some text '. get_permalink();
?>
<a href="<?php echo $link ?>">mail to a friend</a>
There's the wp_mail($to, $subject, $message, $headers, $attachments);
function for such things.
Furthermore there's a function called get_permalink();
. And another one called get_the_title();
.
You can combine them in a function:
function wpse25552_mail_permalink()
{
global $post;
$post_id = $post->ID;
$title = get_the_title( $post_id );
$subject = sprintf( __('I want to share %1$s with you', YOUR_TEXTDOMAIN ), $title );
$permalink = get_permalink( $post_id );
$message = sprintf( __("Yo! Look what I've found here: %1$s", YOUR_TEXTDOMAIN), $permalink );
// ... stuff for $to, $subject, etc.
wp_mail($to, $subject, $message, $headers, $attachments);
}
Note, that you have to replace YOUR_TEXTDOMAIN
with your themes textdomain string. Else you can leave it out (don't forget to delete the comma too).