Headless WordPress – Issue with plugin path

I understand the question and answer are from more than a year ago, but I just wanted to add some additional information in hopes it might be useful for future visitors of this Question.


Recently, while setting up a Headless WordPress CMS with Roots Bedrock, I came across the same issue and solved it with a slightly different version of your solution. I applied points 1 and 2 exactly the same, but did 3 a bit different.
Instead of adding the new line, I changed the declaration of the WP_CONTENT_URL constant from this:

Config::define('WP_CONTENT_URL', Config::get('WP_HOME') . Config::get('CONTENT_DIR'));

to this:

Config::define('WP_CONTENT_URL', Config::get('WP_HOME_ADMIN') . Config::get('CONTENT_DIR'));

This solved the backend plugins paths and also the active theme’s backend assets paths.


But there was one final error: The WordPress REST API endpoint wasn’t accessible in the backend, because it was being generated with the get_home_url() function, which returns the REST API endpoint appended to the frontend URL, instead of the get_site_url().

Looking for solutions for fixing the REST API URL I came across this post answer where the post author provides this filter function you can paste into your active theme’s functions.php file for replacing the REST API URL’s base with that of the backend URL:

/*
 * Fix Roots Bedrock WP REST API base endpoint
 */
add_filter( 'rest_url', function( $url ) {
    $pattern = '/(\S+)(\/wp\/?)$/';
    $siteURL = preg_replace( $pattern, '${1}', site_url() );
    $url = str_replace( home_url(), $siteURL, $url );
    
    return $url;
} );

The function replaces the Frontend URL with the Backend URL, and also removes the /wp part of the Roots Bedrock WordPress backend URL.