我偶然发现了这篇文章,它几乎完全符合我的需要。但我使用的是页面生成器,在模板中插入会产生不希望的结果。
我一直在尝试将这段代码转换成一个短代码,但唉,我不知道我在做什么。有人能帮忙吗?
Download button for Featured Image in every post - automatically
我偶然发现了这篇文章,它几乎完全符合我的需要。但我使用的是页面生成器,在模板中插入会产生不希望的结果。
我一直在尝试将这段代码转换成一个短代码,但唉,我不知道我在做什么。有人能帮忙吗?
Download button for Featured Image in every post - automatically
您可以使用add_shortcode
函数为您的站点注册自定义快捷码。比如像这样,
// add to (child) theme\'s functions.php
function my_download_featured_image_link( $atts, $content = \'\' ) {
// shortcode should return its output
return sprintf(
\'<a class="download_image" href="%s">%s</a>\', // html output of the shortcode
esc_url( get_the_post_thumbnail_url(null, \'full\') ), // defaults to current global $post
esc_html__( \'Download featured image\', \'textdomain\' ) // translatable anchor text
);
}
add_shortcode( \'my_download_featured_image\', \'my_download_featured_image_link\' );
要使用快捷码,请添加[my_download_featured_image]
到您的帖子内容。或者,您可以使用the_content
筛选以在帖子内容末尾自动添加下载链接。链接输出可能需要一些调整,才能与您正在使用的页面生成器很好地配合使用。
// add to (child) theme\'s functions.php
function my_download_featured_image_link_after_content( $content ) {
if ( is_singe() || has_post_thumbnail() ) {
return $content . sprintf(
\'<a class="download_image" href="%s">%s</a>\',
esc_url( get_the_post_thumbnail_url(null, \'full\') ),
esc_html__( \'Download featured image\', \'textdomain\' )
);
} else {
return $content;
}
}
add_filter( \'the_content\', \'my_download_featured_image_link_after_content\' );
我不能在我的主题中使用cssfunctions.php我尝试使用link标签包含css,但它只在第一页加载,然后当我打开其他页面(例如示例页面)时,我不加载任何样式,我该如何做?代码如下:function theme_styles() { wp_enqueue_style( \'style\', get_template_directory_uri() . \'/style.css\' ); wp_enqueue_style( \'bootstrap\', get_te