简体   繁体   中英

Wordpress local development site theme assets point outside of install directory

Working on a custom WordPress site where all the links on the theme are like this: href="/wp-content/...", Somehow this seems to work for the other developers but it doesn't work on my local development setup (MAMP). All these links to images and pages end up pointing to the root of my local server and not to the subdirectory where the installation lives, which results in a lot of files and theme assets not being found.

All I need is to do some quick front end and commit without editing the template so much that it becomes a problem to the other devs working on it.

I was wondering if there was a temporary solution so that the links go to the subdirectory and not the root? ie: ' http://localhost/WPSITE/wp-content/ ...', instead of ' http://localhost/wp-content/ ...'

Hope it makes sense!

You can use this script in footer.php file

<script>

    jQuery(document).ready(function(){

        var find_str = "/wp-content/";
        var replace_with = "http://localhost/WPSITE/wp-content/";

        $('img').each(function (index, value) {

            var src = jQuery(this).attr('src');

            if(src.indexOf(find_str) != -1) {
                console.log(find_str);

                src = src.replace(find_str, replace_with);
                jQuery(this).attr('src', src);
            }

        });
    });

</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM