I would also love some help with this. While I am using GenerateBlocks and its dynamic data, it appears to be the same issue.
The documentation for the Files field suggests that “By default, Pods will not link to the file URL when displaying.”
Is there a way to change this default behavior for use with DIVI/Generate Blocks/ Query Loops, and without using templates and short codes?
Thread Starter
kaostc
(@kaostc)
Hi @complexe , I found a workaround to use the url of a file in a button module link, I share it in case it suitable for you also:
1. Creating a text module with the magic tag that Yousef shared above.
[pods name="project" use_current="1"]
<span id="enlace-boton">{@doc_principal_proyecto._src}</span>
[/pods]
- Hiding this text module (but using custom CSS, not by module controls, in other case it won’t work)
- Creating a code module, with a jQuery snippet that copies the link from the text to the button link:
<script>
$(document).ready(function(){
$("#boton-documento").attr("href", $("#enlace-boton").text())
});
</script>
Workarounds like the one posted by @kaostc above are necessary when working with third-party user interfaces such as Divi, GenerateBlocks, Elementor, and others because the authors of those interfaces decide what data gets associated with the menu items.
Page Builders with user interfaces closely associated to templates
Because each of those editors closely associates the presented menus with the stylization of their templates, it’s not usually simple to change their behavior unless those developers provide filters.
Working around by editing after the page renders
The solution provided works around the challenge by outputting the value from Pods in plain HTML, then using JavaScript to take a value from that custom HTML and attach it to the builder output after the page renders.
Alternative workarounds
When an existing template, page builder, plugin, or theme outputs highly customized templates that don’t integrate with custom data structures as intended, workaround almost always involve one of these:
- Check third-party plugin code or documentation for PHP filters, such as
apply_filters() to modify data.
- Modify HTML output with JavaScript, as above.
- Modify HTML output with PHP, such as with
ob_start() and DOM functions. This is necessary over JavaScript if the content matters for search engines or other non-JavaScript-enabled visitors.
Attachment ID to URL
The WordPress function for getting an attachment URL from the attachment ID is wp_get_attachment_url()