Remove plus sign in the subject of email sharing

Hi,

We have issue while sharing the posts and products via Email sharing option. The sharing option is working fine but email received after sharing has plus(+) sign in place of space used for the title of post and products at the subject of email.

For Example while sharing below link we receive email with subject as “Corn+Rose+Conditioner+With+Hibiscus+Extract+–+350+ml”
https://www.hamroshringar.com/product/corn-rose-conditioner-with-hibiscus-extract-350-ml/

Hoping for solution.

Thank you and best regards.

Hello Bibhash Karn,

Thanks for writing in!

The plus sign in the email subject is the result of the encoding of the post titles. If you want to remove this plus sign, you will need to modify the classic social sharing element. To do that and prevent the plus sign from appearing, since your child theme is set up, please add the following code in your child theme’s functions.php file

// Custom Social Share
// =============================================================================

function custom_x_shortcode_share( $atts ) {
  extract( shortcode_atts( array(
    'id'          => '',
    'class'       => '',
    'style'       => '',
    'title'       => '',
    'share_title' => '',
    'facebook'    => '',
    'twitter'     => '',
    'google_plus' => '',
    'linkedin'    => '',
    'pinterest'   => '',
    'reddit'      => '',
    'email'       => '',
    'email_subject' => ''
  ), $atts, 'x_share' ) );

  $share_url        = urlencode( get_permalink() );

  if ( is_singular() ) {
    $share_url = urlencode( get_permalink() );
  } else {
    global $wp;
    $share_url = urlencode( home_url( ($wp->request) ? $wp->request : '' ) );
  }

  if ( is_singular() ) {
    $share_title = ( $share_title    != '' ) ? esc_attr( $share_title ) : get_the_title();
  } else {
    $share_title = ( $share_title    != '' ) ? esc_attr( $share_title ) : apply_filters( 'the_title', get_page( get_option( 'page_for_posts' ) )->post_title) ;
  }

  $share_source     = urlencode( get_bloginfo( 'name' ) );
  $share_image_info = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
  $share_image      = ( function_exists( 'x_get_featured_image_with_fallback_url' ) ) ? urlencode( x_get_featured_image_with_fallback_url() ) : urlencode( $share_image_info[0] );

  if ( $linkedin === 'true' ) {
    $share_content = urlencode( cs_get_excerpt_for_social() );
  }

  $tooltip_attr = cs_generate_data_attributes_extra( 'tooltip', 'hover', 'bottom' );

  $id          = ( $id          != ''     ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class       = ( $class       != ''     ) ? 'x-entry-share ' . esc_attr( $class ) : 'x-entry-share';
  $style       = ( $style       != ''     ) ? 'style="' . $style . '"' : '';
  $title       = ( $title       != ''     ) ? $title : csi18n('shortcodes.share-title');
  $facebook    = ( $facebook    == 'true' ) ? "<a href=\"#share\" {$tooltip_attr} class=\"x-share\" title=\"" . csi18n('shortcodes.share-facebook') . "\" onclick=\"window.open('http://www.facebook.com/sharer.php?u={$share_url}&amp;t={$share_title}', 'popupFacebook', 'width=650, height=270, resizable=0, toolbar=0, menubar=0, status=0, location=0, scrollbars=0'); return false;\"><i class=\"x-icon-facebook-square\" " . fa_data_icon('facebook-square') . "></i></a>" : '';
  $twitter     = ( $twitter     == 'true' ) ? "<a href=\"#share\" {$tooltip_attr} class=\"x-share\" title=\"" . csi18n('shortcodes.share-twitter') . "\" onclick=\"window.open('https://twitter.com/intent/tweet?text={$share_title}&amp;url={$share_url}', 'popupTwitter', 'width=500, height=370, resizable=0, toolbar=0, menubar=0, status=0, location=0, scrollbars=0'); return false;\"><i class=\"x-icon-twitter-square\" " . fa_data_icon('twitter-square') . "></i></a>" : '';
  $google_plus = ( $google_plus == 'true' ) ? "<a href=\"#share\" {$tooltip_attr} class=\"x-share\" title=\"" . csi18n('shortcodes.share-google-plus') . "\" onclick=\"window.open('https://plus.google.com/share?url={$share_url}', 'popupGooglePlus', 'width=650, height=226, resizable=0, toolbar=0, menubar=0, status=0, location=0, scrollbars=0'); return false;\"><i class=\"x-icon-google-plus-square\" " . fa_data_icon('google-plus-square') . "></i></a>" : '';
  $linkedin    = ( $linkedin    == 'true' ) ? "<a href=\"#share\" {$tooltip_attr} class=\"x-share\" title=\"" . csi18n('shortcodes.share-linkedin') . "\" onclick=\"window.open('http://www.linkedin.com/shareArticle?mini=true&amp;url={$share_url}&amp;title={$share_title}&amp;summary={$share_content}&amp;source={$share_source}', 'popupLinkedIn', 'width=610, height=480, resizable=0, toolbar=0, menubar=0, status=0, location=0, scrollbars=0'); return false;\"><i class=\"x-icon-linkedin-square\" " . fa_data_icon('linkedin-square') . "></i></a>" : '';
  $pinterest   = ( $pinterest   == 'true' ) ? "<a href=\"#share\" {$tooltip_attr} class=\"x-share\" title=\"" . csi18n('shortcodes.share-pinterest') . "\" onclick=\"window.open('http://pinterest.com/pin/create/button/?url={$share_url}&amp;media={$share_image}&amp;description={$share_title}', 'popupPinterest', 'width=750, height=265, resizable=0, toolbar=0, menubar=0, status=0, location=0, scrollbars=0'); return false;\"><i class=\"x-icon-pinterest-square\" " . fa_data_icon('pinterest-square') . "></i></a>" : '';
  $reddit      = ( $reddit      == 'true' ) ? "<a href=\"#share\" {$tooltip_attr} class=\"x-share\" title=\"" . csi18n('shortcodes.share-reddit') . "\" onclick=\"window.open('http://www.reddit.com/submit?url={$share_url}', 'popupReddit', 'width=875, height=450, resizable=0, toolbar=0, menubar=0, status=0, location=0, scrollbars=0'); return false;\"><i class=\"x-icon-reddit-square\" " . fa_data_icon('reddit-square') . "></i></a>" : '';


  if ( $email       == 'true' ) {

    $email_subject = esc_attr( ( $email_subject != '' ) ? cs_decode_shortcode_attribute( $email_subject ) : csi18n('shortcodes.share-email-subject') );
    $mail_to_subject = esc_attr( $share_title );
    $mail_to_url = esc_url( get_permalink() );

    $mail_to = "mailto:?subject=$mail_to_subject&amp;body=$email_subject $mail_to_url";

    $email = "<a href=\"{$mail_to}\" {$tooltip_attr} class=\"x-share email\" title=\"" . csi18n('shortcodes.share-email') . "\"><span><i class=\"x-icon-envelope-square\" " . fa_data_icon('envelope-square') . "></i></span></a>";

  } else {
    $email = '';
  }



  $output = "<div {$id} class=\"{$class}\" {$style}>"
            . '<p>' . $title . '</p>'
            . '<div class="x-share-options">'
              . $facebook . $twitter . $google_plus . $linkedin . $pinterest . $reddit . $email
            . '</div>'
          . '</div>';

  return $output;
}

add_action('wp_head', 'change_social_share_to_custom');

function change_social_share_to_custom() {
  remove_shortcode( 'x_share' );
  add_shortcode( 'x_share', 'custom_x_shortcode_share' );
}
// =============================================================================

What has changed from the original code? It is the line:

if ( is_singular() ) {
    $share_title = ( $share_title    != '' ) ? esc_attr( $share_title ) : get_the_title();
  } else {
    $share_title = ( $share_title    != '' ) ? esc_attr( $share_title ) : apply_filters( 'the_title', get_page( get_option( 'page_for_posts' ) )->post_title) ;
  }

The code encodes the post/page titles were:

if ( is_singular() ) {
    $share_title = ( $share_title    != '' ) ? esc_attr( $share_title ) : urlencode( get_the_title() );
  } else {
    $share_title = ( $share_title    != '' ) ? esc_attr( $share_title ) : urlencode( apply_filters( 'the_title', get_page( get_option( 'page_for_posts' ) )->post_title) );
  }

Be very careful when copying and pasting the code. One single quote mistake can create a fatal error in your site.

Please note that custom coding is outside the scope of our support. Issues that might arise from the use of custom code and further enhancements should be directed to a third party developer.

We would love to know if this has worked for you. Thank you.

March 2021 Update: The above code example has been adjusted to account for a change to a function name.

Thank you for your response and support.

It worked for me and the issue has been solved via removing urlencode(). Thank you for mentioning the changes at the code.

I am little bit confused as why there is encoding used for the post titles at the email subject by default at the theme. Will removing encoding from email subject create any issue in future?

Thank you and best regards.

Hi Bibhash Karn,

It should be okay, you can revert it back anytime. And it mostly depends on the ap/program being used.

Thanks!

Hello,

Thank you for the reply and confirmation.

Thank you and best regards.

You’re welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.