无法在作为函数注入的按钮上添加自定义字段作为 href

问题描述 投票:0回答:0

当我尝试在我使用函数注入 wordpress 网站的按钮上添加自定义字段文件作为 href 下载时,我遇到了问题。

function inject_link_into_post_feed() {
    // Output the <a> tag inside the "item-main" div
    echo '<script>
            jQuery(document).ready(function($) {
                var fileLink = "'.get_field('file_link').'";
                var downloadLink = $("<a>").attr({
                    "href": fileLink,
                    "download": "true"
                }).text("Download Guide");
                $(".books-feed .item-main").append(downloadLink);
            });
        </script>';
}
add_action('wp_footer', 'inject_link_into_post_feed');

代码将按钮拉入特定的 html 片段,但自定义字段的下载链接似乎不起作用。

这是下载按钮正在拉到的网站链接。你可以在明信片上看到这个。

https://thirst.io/guides/

有人能告诉我我为自定义字段编写的代码哪里出错了,无法通过。

javascript php html wordpress
© www.soinside.com 2019 - 2024. All rights reserved.