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

相关文章
相关推荐
froginwe11几秒前
R 矩阵:解析与应用
开发语言
_OP_CHEN4 分钟前
C++基础:(十六)priority_queue和deque的深度解析
开发语言·c++
C++ 老炮儿的技术栈9 分钟前
include″″与includ<>的区别
c语言·开发语言·c++·算法·visual studio
Vallelonga9 分钟前
Rust 设计模式 Marker Trait + Blanket Implementation
开发语言·设计模式·rust
CHANG_THE_WORLD16 分钟前
PDFium导出pdf 图像
开发语言·c++·pdf
owCode30 分钟前
4-C++智能指针
开发语言·c++
liu****40 分钟前
10.queue的模拟实现
开发语言·数据结构·c++·算法
写不来代码的草莓熊41 分钟前
vue前端面试题——记录一次面试当中遇到的题(9)
前端·javascript·vue.js
哦你看看1 小时前
学习Python 03
开发语言·windows·python
JinSo1 小时前
pnpm monorepo 联调:告别 --global 参数
前端·github·代码规范