아래의 코드를 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 작품
게시글 목록
| 번호 | 제목 |
|---|---|
| 23606 | |
| 23598 | |
| 23585 | |
| 23579 | |
| 23578 | |
| 23564 | |
| 23550 | |
| 23549 | |
| 23548 | |
| 23529 | |
| 23510 | |
| 23507 | |
| 23481 | |
| 23471 | |
| 23453 | |
| 23452 | |
| 23450 | |
| 23436 | |
| 23428 | |
| 23404 | |
| 23396 | |
| 23389 | |
| 23380 | |
| 23369 | |
| 23350 | |
| 23337 | |
| 23317 | |
| 23307 | |
| 23298 | |
| 23290 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기