当我尝试在我使用函数注入 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 片段,但自定义字段的下载链接似乎不起作用。
这是下载按钮正在拉到的网站链接。你可以在明信片上看到这个。
有人能告诉我我为自定义字段编写的代码哪里出错了,无法通过。