Forum

Thread tagged as: Question, Problem, Blog

Create absolute path for image upload

On a blog post, how can I make the image upload to the post an absolute path without having to hard code it into the HTML?

Jose Reyes

Jose Reyes 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It should be root-relative by default. Is that not what you're seeing? Could you give an example?

Yes, you are correct.

At the moment when the image is uploaded the path is as follows: src="/perch/resources/image4-61-.jpg

I would like the path to be absolute like so: src="https://www.mywebsite.com/perch/resources/image4-61-.jpg

Is that possible to do without hard-coding each image in the HTML mode of the WYSIWYG?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think so. What's the use case for that?

The client wants an RSS driven email campaign with Mailchimp. She wants the complete post to be sent as posted on the blog post itself. When the campaign is triggered and everything is sent, the complete post does display-with the exception of the images. I checked with Mailchimp as to why the images are not displaying, and the path is the issue. They are relative to the site. If the images were absolute paths, then they would show up on the campaign email blast.

https://sharonpalmer.com/blog.php

https://sharonpalmer.com/rss.php

Any suggestions on how to fix this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use

<perch:setting id="siteURL" />

which will output the value of the "Website URL" field on the Settings page. Does that help?

I'm afraid not...

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Why doesn't that help? I'm not sure from that what you have tried?

I plugged in the line of code as suggested, but the image paths on the RSS feed still show as relative paths.

It still shows up...

<img style="" src="/perch/resources/1a-1-.jpg">

Need it to come up as... <img style="" src="https://www.sharonpalmer.com/perch/resources/1a-1-.jpg">

This is the RSS Feed URL https://sharonpalmer.com/rss.php

Please review and advise.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us that part of your template?

On the rss page itself I have the following code...

<rss version="2.0" xmlns:atom="https://www.w3.org/2005/Atom">
    <channel>
        <title>Sharon Palmer, RD</title>
        <link>https://sharonpalmer.com/blog/</link>
        <description>Sharon Palmer is a registered dietitian that writes about plant based nutrition. </description>
        <atom:link href="https://sharonpalmer.com/blog.php" rel="self" type="application/rss+xml" />
        <?php
            perch_blog_custom(array(
                'template'=>'blog/rss_post.html',
                'count'=>10,
                'sort'=>'postDateTime',
                'sort-order'=>'DESC'
                ));
        ?>
    </channel>
</rss>

On the template page, to show the complete post I have the following code...

        <item>
           <title><perch:blog id="postTitle" /></title>
           <link>https://www.sharonpalmer.com/<perch:blog id="postURL" /></link>
           <guid>https://www.sharonpalmer.com/<perch:blog id="postURL" /></guid>
           <description><![CDATA[<perch:blog id="postDescHTML" encode="false" />]]>
            </description>
           <pubDate><perch:blog id="postDateTime" format="D, d M Y H:i:s O" /></pubDate>
        </item>

I hope I answered your question correctly.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah, so the images are not structured data, but just inline within a post?

Correct, according to the documentation the following line is what is needed for the entire blog post to show.

<description><![CDATA[<perch:blog id="postDescHTML" encode="false" />]]></description>

If it broke it down, I would be able to just hard-code the URL before the loop, but it's all dynamically embedded in this line of code.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which editor are you using?

I use a combination of condeanywhere.com when I'm not at my computer, or need to do some coding on my iPad on the go. On my laptop, I use Dreamweaver.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I mean for Perch - are you using MarkItUp or Redactor or CKEditor or TinyMCE or something else?

I have this exact issue, using Markitup. I want to have absolute URLS for images uploaded in a textarea in a blog post (for RSS purposes). Is this possible? Seems like it should be a Markitup setting or something?