Among the dynamic capabilities that Smart Auto Featured Image offers, one of them is the ability to generate content based on custom functions.
Custom functions must be inserted through a Text layer.
The syntax to use for custom function is the following:
{{my_function_name()}}
In order for the custom function to render something, the function must be declared in php, typically in your theme’s functions.php file.
The function name MUST be prefixed by “safi_” (without quotes)
In our case, the function would be called safi_my_function_name()
.
function safi_my_function_name($data) { //removes all occurence of "the" $str = str_ireplace('the', '', $data['title']); //removes extra white spaces return trim(preg_replace('/\s+/', ' ', $str)); }
Each custom function has a $data parameter that contains contextual data about the current post.
$data offsets available:
$data['post']
: (object) post data.$data['author']
: (object) post author.$data['date']
: (string) post date.$data['categories']
: (array) post categories.$data['meta']
: (object) post metas.$data['tags']
: (array) list of tags.$data['title']
: (string) post title.$data['type']
: (string) post type.
Here is an example below using the above custom function:
In the editor, our Text layer contains our custom function name
Notice how our article here starts by “The”
Now if we preview our template, the word “The” disappeared, according to our custom function !