Skip to content

Instantly share code, notes, and snippets.

@haet
Last active October 4, 2018 09:29
Show Gist options
  • Select an option

  • Save haet/e2983b006185b5fd915c7124e3cb9f13 to your computer and use it in GitHub Desktop.

Select an option

Save haet/e2983b006185b5fd915c7124e3cb9f13 to your computer and use it in GitHub Desktop.
Add custom CSS to WP HTML Mail WordPress E-Mails
/**
* Add custom CSS to WP HTML Mail WordPress E-Mails
*/
add_filter( 'haet_mail_modify_styled_mail', function( $email_html ){
$custom_css = '
.container-padding{
padding-left: 60px;
padding-right: 0;
}
h1{
border-bottom: 2px solid black;
}
';
$custom_mobile_css = '
.container-padding{
padding-left: 10px;
padding-right: 10px;
}
';
$email_html = str_replace( '/**** ADD CSS HERE ****/', $custom_css . '/**** ADD CSS HERE ****/', $email_html );
$email_html = str_replace( '/**** ADD MOBILE CSS HERE ****/', $custom_mobile_css . '/**** ADD MOBILE CSS HERE ****/', $email_html );
return $email_html;
});
@bishless

Copy link
Copy Markdown

Nice! Thanks for making this available.

@Joe-Bloggs

Copy link
Copy Markdown

Thanks, that's awesome! Will it make its way into the plugin itself in one of the new updates?

@nineyards

Copy link
Copy Markdown

Im confused. In the plugin FAQ it says

You can add your own CSS code for desktop and mobile. Just add this example to your (child-)themes functions.php and customize it:

add_filter( 'haet_mail_css_desktop', function( $css ){ $css .= ' h1{ border-bottom: 2px solid green; } '; return $css; });

However, this does not work and there is no haet_mail_css_desktop defined in the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment