We do not wanted to use eval
, so php code execution is not possible inside Template.
However, there is alternatives. You can add a shortcode to solve your needs. Shortcode return value can be dynamic.
To register a new shortcode for W4 Post list, use w4pl/get_shortcodes
filters.
add_filter('w4pl/get_shortcodes', 'w4pl_extra_shortcode', 30);
function w4pl_extra_shortcode( $s ){
$s['myDynamicField'] = array(
'group' => 'Post',
'callback' => 'myDynamicFieldAction',
'desc' => ''
);
return $s;
}
- myDynamicField: This is the name of the shortcode that you will use on Template field. Like
[myDynamicField]
- group: this is where it will be visible on template group. not important
- callback: required. A php callback function name, Or a public static class method name. Which will be used to replace the content of the shortcode.
- desc: textual description of the shortcode, it’s displayed on the Documentation page.
The following function is similar to WP’s basic shortcode callback function.
function myDynamicFieldAction( $attrs, $content ){
$return = '';
$return .= 'Good ';
if( date('h') > 5 && date('h') < 11 ){
$return .= 'Morning';
}
elseif( date('h') < 17 ){
$return .= 'Afternoon';
}
elseif( date('h') < 20 ){
$return .= 'Evening';
}
elseif( date('h') < 20 ){
$return .= 'Night';
}
return $return;
}
Hope this helps.