Is there a way of creating text that updates dynamically? For example “I am 21 years old” where 21 is generated by a date in code or plugin.
Thanks
Rob
Hey fanlokbun,
Thank you for the inquiry.
Yes, this should be possible with a custom field and shortcodes. Please check the following documentation for more info.
// https://codex.wordpress.org/Shortcode_API
// https://wordpress.org/documentation/article/assign-custom-fields/
Example:
add_shortcode('avs_iam_shortcode', 'avs_iam_shortcode_cb');
function avs_iam_shortcode_cb($atts){
extract(shortcode_atts(array(
'age' => 21,
), $atts));
if(!isset($atts[0])) return;
$field = esc_attr($atts[0]);
global $post;
$post_id = (NULL === $post_id) ? $post->ID : $post_id;
return "I am ". get_post_meta($post_id, $field, true) ." years old";
}
Shortcodes:
[avs_iam_shortcode age=88]
You have to add the “age” custom field in the post.
Best regards,
Ismael
Many thanks Ismael. I’m having fun playing with this.
Hi,
Great, I’m glad that Ismael could help you out. Please let us know if you should need any further help on the topic, or if we can close it.
Best regards,
Rikard
Thanks Rikard you can close the topic.
Hi fanlokbun,
Thanks for using Enfold and have a great day!
Best regards,
Nikko