wordpress相册gallery自定义

把这段代码添加到functions.php就可以实现相册gallery输出的自字义

add_filter( 'the_content', 'wpdocs_show_gallery_image_urls' );

function wpdocs_show_gallery_image_urls( $content ) {
    global $post;

    if( ! is_singular() ) return $content;

    if( ! has_shortcode( $post->post_content, 'gallery' ) ) return $content;

    $gallery = get_post_gallery_images( $post );

    $image_list = '<ul>';

    foreach( $gallery as $image_url ) {
        $image_list .= '<li>' . '<img src="' . $image_url . '">' . '</li>';
    }

    $image_list .= '</ul>';

    $content .= $image_list;

    return $content;
}

原文链接 https://www.zhanyes.com/code/6052.html

相关文章
相关推荐
c4fx4 分钟前
Delphi5利用DLL实现窗体的重用
开发语言·delphi·dll
罗_三金5 分钟前
前端框架对比和选择?
javascript·前端框架·vue·react·angular
Redstone Monstrosity12 分钟前
字节二面
前端·面试
东方翱翔19 分钟前
CSS的三种基本选择器
前端·css
鸽芷咕28 分钟前
【Python报错已解决】ModuleNotFoundError: No module named ‘paddle‘
开发语言·python·机器学习·bug·paddle
Jhxbdks37 分钟前
C语言中的一些小知识(二)
c语言·开发语言·笔记
java66666888837 分钟前
如何在Java中实现高效的对象映射:Dozer与MapStruct的比较与优化
java·开发语言
Violet永存38 分钟前
源码分析:LinkedList
java·开发语言
代码雕刻家40 分钟前
数据结构-3.1.栈的基本概念
c语言·开发语言·数据结构
Fan_web41 分钟前
JavaScript高级——闭包应用-自定义js模块
开发语言·前端·javascript·css·html