Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Nicolas Lemoine

    (@nlemoine)

    Hi Garrett,

    You want to be able to change the subject of the email?
    This subject is part of the content of each email and can’t be customized as it depends of the sender (WordPress, any plugin, etc.).

    N.

    Thread Starter Garrett Hyder

    (@garrett-eclipse)

    Hi @hellonico,

    Sorry for the delay was away for a few days.

    I don’t want to affect the subject in anyway, rather I’d like to utilize a %subject% tag within the template which would dynamically pull the subject in just like the %content%, %date%, %time% and %admin_email% tags.

    This way I can have the email be more like a transcript which gives the subject within the content as well as the content.

    I know not a standard request but is coming from a client.

    Cheers

    @hellonico,

    I too would like this, exactly what Garret wants.

    Hi @hellonico

    Any idea if this can/will be implemented or not?

    Thanks

    Thread Starter Garrett Hyder

    (@garrett-eclipse)

    Hi Hyflex,

    Thanks for the poke reminder on this, I forgot to post an existing solution to get the %subject% tag to work.

    The plugin provides a filter we can latch onto for this purpose;

    How can I add my own tags ?
    You can filter the tags array and add your replacements. Let’s say you want to randomly display some sponsored links somewhere in your email template:

    add_filter('wpbe_tags', 'add_my_tags');
    function add_my_tags( $tags ) {
        $ads = array('<a href="#">Sponsored link 1</a>', '<a href="#">Sponsored link 2</a>', '<a href="#">Sponsored link 3</a>');
        $tags['sponsored_link'] = $ads[array_rand($ads, 1)];
        return $tags;
    }

    The key of the array sponsored_link will be a new tag (%sponsored_link%) you can include. It will be randomly replaced with one of your sponsored links.

    The example above is taking sponsored links as an additinonal content but you can imagine anything like including lastest posts, a quote of the day or whatever. You can place this function in your functions.php theme file or in a plugin.

    Reference: https://wordpress.org/plugins/wp-better-emails/faq/

    So using this filter we can intercept the ‘subject’ through the $phpmailer global to populate this on the existing plugin version without modifying the core code, see below;

    // Add Filter to WPBE to introduce the %subject% tag
    function add_subject_tag( $tags ) {
    	global $phpmailer;
    	$tags['subject'] = $phpmailer->Subject;
    	return $tags;
    }
    add_filter('wpbe_tags', 'add_subject_tag');

    *Simply throw this into your functions.php

    I branched the repo and will update with a PR containing a modified version of the plugin as I still feel it should be available as part of the core plugin.

    Cheers

    Thread Starter Garrett Hyder

    (@garrett-eclipse)

    Alright I’ve provided a code fix for the plugin.

    Opened Github Issue – https://github.com/nlemoine/wp-better-emails/issues/16

    Forked – https://github.com/garrett-eclipse/wp-better-emails

    Pull Request – https://github.com/nlemoine/wp-better-emails/pull/17

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Provide a %subject% tag’ is closed to new replies.