safi_postprocess_text

Filters a text layer after it has been processed. At this stage, any dynamic text would already have been transformed into its final value.

HTML can be passed into the text.

/**
 * Change the styles of the text layers that start with one of the listed keywords
 */
add_filter('safi_postprocess_text', function ($text, $layer, $post_data) {
    $keywords = ['how to', 'best', 'why', 'top 10'];

    foreach ($keywords as $kw) {
        //Check if the word is at the beginning of the string
        if (stripos($text, $kw) === 0) {
            //Preserve case while replacing data and applies a bold+italic style
            $text = preg_replace("/$kw/i", "<span style=\"font-weight:600;font-style:italic;\">\$0</span>", $text);
        }
    }

    return ($text);
}, 10, 3);
Was this page helpful?