✨ Professional WordPress development, custom website builder, efficient on-line, cooperate and enjoy optimization services! 🚀
1. Basic ACF Shorthand Syntax
ACF provides a short code The basic syntax is as follows:
Among them.field name
needs to be replaced with the name of the custom field you created in ACF (Field Name
).
typical example
If you create a phone_number
field and assign it a value 123-456-7890
, which can be called in articles or pages using the following shortcode:
Show results:
If the default The short code does not fulfill the requirement, you can create your own short code. For example, get the ACF field of the current article:
function custom_acf_shortcode($atts) {
$atts = shortcode_atts(array(
'field' => '', ''
), $atts);
if ($atts['field']) {
return get_field($atts['field']);
}
return '';
}
add_shortcode('my_acf', 'custom_acf_shortcode');
You can then use it in a post or page:
[my_acf field="phone_number"]
summarize
goal | Usage |
---|---|
Get the fields of the current article |
|
Get the fields for a specific article |
|
Get the current user's fields |
|
Getting the fields of the Options page |
|
Calling WooCommerce Product Fields |
|
Customized Short Codes | utilization add_shortcode() establish |
I hope this tutorial was helpful!