Preheader in custom template

Discussion in 'Tips and tricks' started by kosir, Mar 10, 2018.

  1. kosir

    kosir Member

    Joined:
    Sep 11, 2017
    Messages:
    46
    Likes Received:
    11
    S.E:
    2019-03-20 15:18:30
    L.T:
    Regular
    L.C:
    2
    Hello,

    I created a custom template and everything except preheader is showing. I am using the preheader field but it's not added to my emails.

    My question, how can I add text from preheader field to my template? It's not listed under available tags.
     
  2. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    9,314
    Likes Received:
    2,208
    @kosir - the preheader isn't shown in the email template. The preheader is used for when the emails is viewed in the email client, before it is clicked, to show a small excerpt about the email content.
     
  3. kosir

    kosir Member

    Joined:
    Sep 11, 2017
    Messages:
    46
    Likes Received:
    11
    S.E:
    2019-03-20 15:18:30
    L.T:
    Regular
    L.C:
    2
    Hey,

    Yes, but it must be somehow added to the email source/original.
    Right now the first line of my email is displayed where preheader should be in gmail. Even if i look at the source preheader is not there.
    So there must be some tag that I must add to the template so the preheader will be added.
     
  4. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    9,314
    Likes Received:
    2,208
    @kosir - mailwizz tries to inject that right after the opening <body> tag, so you must have a body tag and a head tag:
    PHP:
    /**
    * @param $emailContent
    * @param $preheader
    * @param Campaign $campaign
    * @return mixed
    */
    public static function injectPreheader($emailContent$preheaderCampaign $campaign)
    {
        
    $hideCss      'display:none!important;mso-hide:all;';
        
    $style        sprintf('<style type="text/css">span.preheader{%s}</style>'$hideCss);
        
    $emailContent str_ireplace('</head>'$style '</head>'$emailContent);
        
    $preheader    sprintf('<span class="preheader" style="%s">%s</span>'$hideCss$preheader);
        return 
    preg_replace('/<body([^>]+)?>/six''$0' $preheader$emailContent);
    }
     
  5. kosir

    kosir Member

    Joined:
    Sep 11, 2017
    Messages:
    46
    Likes Received:
    11
    S.E:
    2019-03-20 15:18:30
    L.T:
    Regular
    L.C:
    2
    Thanks!
     

Share This Page