Support » Plugin: Custom Field Template » Media Library image inserted into CFT has relative URL

  • Resolved darkhorse20

    (@darkhorse20)


    I upgraded Custom Field Template to version 2.2.x . I set up a custom textarea field like I usually do but I noticed something very strange when adding content to the textarea.

    When inserting an image from the Media Library, the URL of the image is no longer an absolute URL like ‘http://localhost/wp-content/uploads/2014/04/test-image.png’ . The editor keeps changing the URL to ‘../wp-content/uploads/2014/04/test-image.png’. Even if I manually enter the HTML so the URL is absolute, the Custom Field Template textarea editor keeps change it back to a relative URL.

    The Custom Field Template plugin was not doing this before.

    https://wordpress.org/plugins/custom-field-template/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Just want to note that I am having this exact same problem.

    However, it seems to go further than just the absolute/relative URL issue. One of my custom field textareas will not allow me to make any changes at all. Any change I make to the text or HTML is not saved when I update the page.

    Jep, I got this problem aswell – glad to hear that I am not the only one! Did anybody find a solution yet?

    This bug is really starting to irritate me. It just happened out of nowhere again. Yesterday, it wasn’t happening. Today, no core or plugin updates, nothing new installed and the URL’s in the text area of the Custom Field Template keep changing to relative URLs now. Anyone ever find some kind of fix yet?

    Ok. I found a fix for this. I’m not sure if this is THE fix but it worked for me.

    It appears CFT plugin does not like it when page templates are inside a subfolder in the main theme folder. The issue was happening on the page template that was located in:

    website.tld/wp-content/themes/ThemeName/page-templates/homepage.php

    I moved the template file in the root directory of the theme folder like this:

    website.tld/wp-content/themes/ThemeName/homepage.php

    Then I reconfigured the CFT settings for the homepage.php template (I updated the ‘Page Template file name(s) (comma-deliminated):’ field) and it fixed it. No more relative path URL’s.

    I’ve tried this on two websites and it worked. Let me know if this works for anyone else and I will marked this post as resolved.

    Thanks for the tip darkhorse!

    However in my custom theme all template files are already in the root directory. The installation of WordPress itself is running out of a subdirectory called /wp though. So perhaps that’s related to the problem.

    I spent another half hour trying to find a solution for my unique circumstance today, but after coming up empty handed I have temporarily ditched the plugin in favor of Advanced Custom Fields which seems to be working just fine.

    Yeah, that fix I posted isn’t a long term solution as the URL’s in the text areas keep reverting back.

    However, I did find something that seems to work. When the URL keeps reverting back to a relative URL such as ‘../wp-content/uploads/2014/04/test-image.png’ .

    Change the URL so the domain is different than the site URL. So if your domain is mywebsite.com, make the URL so it looks like ‘http://mywebsite-test.com/wp-content/uploads/2014/04/test-image.png’ . Save the post/page. Of course the image will not load because it doesn’t exist on the domain http://mywebsite-test.com . But now, if you go back to the text area, the URL is no longer relative, it is back to absolute. And now you can put the correct URL ‘http://mywebsite.com/wp-content/uploads/2014/04/test-image.png’ , re-save and it should be absolute still. So far this has worked for me multiple times. Hope this works for others as well.

    As a follow up, this relative URL issue appears to be related to the new TinyMCE 4.0 update to WordPress. There is a configuration setting for relative URL’s (http://www.tinymce.com/wiki.php/Configuration:relative_urls) that seems to be turning on for whatever reason. Any how, I’m marking this as resolved. The fix in the previous post is working for me all the time now.

    Darkhorse20 – how can we update this setting? I’m having issues with links and cannot seem to fix without disabling TinyMCE fields entirely. I’m not sure how to update that configuration setting within wordpress, but would like to as that seems like it’s the solution.

    purrdesign, honestly, I’m not sure. I was running just the 2014 Theme with only the Custom Field Template plugin installed and I was still running into this issue. I’ve also seen in this issue on live server environments, as well as on a local server. It’s very hard to narrow down what exactly is causing this to happen because it’s not consistent with everyone.

    I did find some interesting stuff while trying to figure this out. When this issue was happening, I went to the textarea that was having this issue, put it in ‘visual’ mode and copied all the content to the clipboard. Then I went into Dreamweaver and pasted the content into Dreamweaver’s ‘Design’ view. When I took a look at the HTML, some new code showed up that doesn’t appear in the TinyMCE ‘text/code’ view.

    The HTML for the image looked like this:
    <img src="http://localhost/wp-content/uploads/2014/07/filename-th.png" alt="" data-mce-src="../wp-content/uploads/2014/07/filename-th.png">

    It looks likes theres a ‘data-mce-src’ attribute that’s not matching up with the default ‘src’ attribute of the image. It appears that is what’s messing it up.

    Unfortunately, I have no idea how to fix this or how/why this is happening. Hopefully someone who does sees this and posts a fix.

    Is this the same or related issue?: http://wordpress.org/support/topic/tinymce-fields-and-broken-links?replies=6

    If so our code in the above post may fix this too.

    I am having this exact problem! And it’s extremely frustrating!

    I would upgrade to Advanced Custom Fields if I could, (it’s a great plugin), but I’m supporting some very old sites. I used darkhorse20’s solution of putting in an intentionally broken absolute URL, saving, coming back and switching it out for the real URL. It works, but it’s definitely not a long term solution.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Media Library image inserted into CFT has relative URL’ is closed to new replies.