admin管理员组文章数量:1125913
I have created a custom ACF field called Slide URL in the admin post editor. Am I able to use a system/global variable in here to resolve the base URL for the environment that wordpress is installed on? For example, it would be great to use something like: [var:BaseURL]/my-page.
This means that when I move from the staging environment to the production environment I won't need to change the base URL to the new production environment for every post.
Grateful for your help.
I have created a custom ACF field called Slide URL in the admin post editor. Am I able to use a system/global variable in here to resolve the base URL for the environment that wordpress is installed on? For example, it would be great to use something like: [var:BaseURL]/my-page.
This means that when I move from the staging environment to the production environment I won't need to change the base URL to the new production environment for every post.
Grateful for your help.
Share Improve this question asked Feb 6, 2024 at 12:20 wordpressnewbiewordpressnewbie 1 1- Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Bot Commented Feb 7, 2024 at 18:27
1 Answer
Reset to default 0Add the following code to dynamically set the base URL for your ACF custom URL field.
Replace slide_url
with the name of your ACF custom URL field
function custom_acf_slide_url_base_url($value, $post_id, $field) {
// Get the base URL dynamically based on the environment
$base_url = '';
if (strpos(site_url(), 'staging') !== false) {
$base_url = 'https://staging.example.com'; // Replace with your staging URL
} else {
$base_url = 'https://www.example.com'; // Replace with your production URL
}
// Append the relative path to the base URL
$slide_url = $base_url . '/my-page';
return $slide_url;
}
add_filter('acf/load_value/name=slide_url', 'custom_acf_slide_url_base_url', 10, 3);
本文标签:
版权声明:本文标题:migration - How can I dynamically set the base URL of an ACF custom URL field? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736661763a1946451.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论