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
Add a comment  | 

1 Answer 1

Reset to default 0

Add 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);

本文标签: