2026, 새로운 도약을 시작합니다.

그누보드5 링크 썸네일을 게시판 첨부파일 사용하도록 하는 코드 (OG이미지메타테그)

아래의 코드를 head.sub.php의 </head> 위에 삽입

<?php

function override_og_image() {

    $html = ob_get_contents();

    libxml_use_internal_errors(true);

    $dom = new DOMDocument();

    @$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);

    $xpath = new DOMXPath($dom);

    // Find view_image class images

    $images = $xpath->query('//a[@class="view_image"]//img');

    // Extract current OG image

    preg_match('/<meta\s+property="og:image"\s+content="([^"]*)"[^>]*>/i', $html, $matches);

    $defaultImageUrl = isset($matches[1]) ? $matches[1] : 'https://내도메인/이미지';

    // Select random image or fallback

    if ($images->length > 0) {

        $randomIndex = rand(0, $images->length - 1);

        $newImageUrl = $images->item($randomIndex)->getAttribute('src');

        // Validate URL format

        if (!filter_var($newImageUrl, FILTER_VALIDATE_URL)) {

            $newImageUrl = $defaultImageUrl;

        }

    } else {

        $newImageUrl = $defaultImageUrl;

    }

    // Replace OG image meta tag

    $pattern = '/<meta\s+property="og:image"\s+content="[^"]*"[^>]*>/i';

    $replacement = '<meta property="og:image" content="' . htmlspecialchars($newImageUrl, ENT_QUOTES, 'UTF-8') . '">';

    $modified_html = preg_replace($pattern, $replacement, $html);

    ob_clean();

    echo $modified_html;

}

ob_start();

register_shutdown_function('override_og_image');

?>

*클로드ai 작품

|

댓글 2개

감사합니다 ^^

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

그누보드5 팁자료실

번호 제목 글쓴이 날짜 조회
공지 3년 전 조회 4,598
2741 3일 전 조회 111
2740 4일 전 조회 103
2739 1주 전 조회 209
2738 1주 전 조회 217
2737 1주 전 조회 181
2736 1주 전 조회 280
2735 3주 전 조회 281
2734 3주 전 조회 263
2733 1개월 전 조회 265
2732 1개월 전 조회 301
2731 1개월 전 조회 267
2730 1개월 전 조회 226
2729 1개월 전 조회 355
2728 1개월 전 조회 245
2727 1개월 전 조회 422
2726 1개월 전 조회 256
2725 1개월 전 조회 330
2724 1개월 전 조회 358
2723 1개월 전 조회 267
2722 1개월 전 조회 300
2721 1개월 전 조회 211
2720 2개월 전 조회 304
2719 2개월 전 조회 307
2718 2개월 전 조회 202
2717 2개월 전 조회 336
2716 2개월 전 조회 202
2715 2개월 전 조회 311
2714 2개월 전 조회 273
2713 2개월 전 조회 376
2712 2개월 전 조회 289
🐛 버그신고