-1

Trying to add an “email this page” link to an archive page in WordPress/WooCommerce. It’s in the sidebar (so outside the loop)

The code I'm hoping to end up with is

<a href=mailto:?subject="(page_title)"&body="Some text (url_to_the_page_being_viewed)">Email This Page

I’ve tried a bunch of things, such as

<?php
echo '<a href="mailto:?subject=' . the_title() . '&body=' . the_title() . ' - ' . echo get_permalink( get_queried_object_id() ) . '">E-Mail This Page</a>' ; 
?>

But no joy as of yet.

What am I missing?

Phil
  • 1
  • 3

1 Answers1

0

Use this:

global $wp_query;
$catName = $wp_query->query_vars['product_cat'];

$link = home_url().'/product-category/'.$catName;
$title = get_the_title();

echo "<a href='mailto:$link?subject=$title&body=$title'>E-Mail This Page</a>";
Mohammad Yousefi
  • 513
  • 3
  • 12