Skip to content

Instantly share code, notes, and snippets.

@kwcjr
Last active March 2, 2022 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwcjr/5922524b6c068e7b6ea5e5643d12b5db to your computer and use it in GitHub Desktop.
Save kwcjr/5922524b6c068e7b6ea5e5643d12b5db to your computer and use it in GitHub Desktop.
Add custom preview text to wp_mail
<?php
/**
* Plugin Name: Replace Pre-Header Email Text.
* Description: Replace Line 27 with what text you want. This will replace the text just after your Subject - "Your text".
* Author: Keith Crain ( Kronoslabs.io )
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
/**
* Pass custom email header preview text.
*
* @param string 'wp_mail' Hook name to hook function into
* @param string 'klbs_custom_email_header' Function name to be hooked
*/
add_action( 'wp_mail', 'klbs_custom_email_header', 10, 2 );
/**
* Add preview text after subject line.
*/
function klbs_custom_email_header( $email_heading, $email ) {
echo '
<div style="max-height: 0px; overflow: hidden;">
Insert hidden preheader text here.
</div>
<!-- Insert &#847;&zwnj;&nbsp; hack after hidden preview text -->
<div style="max-height: 0px; overflow: hidden;">
&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;&zwnj;&nbsp;
</div>
';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment