KBaord(케이보드) 게시글 내용에 유튜브 쇼츠 주소 입력 문의

1. 정확한 제품 또는 플러그인 이름

kboard

 

2. 상세 내용

유튜브 쇼츠도 삽입하고 싶은데요

아이프레임으로 변경하는 function을 찾아서 

저런 식으로 넣어주니,

쇼츠는 삽입이 안되서요... 

혹시 어떻게 하면 쇼츠도 동영상 출력으로 넣을 수 있을까요?

 

3. 확인 가능한 상세 페이지 주소

 

 

4. 수정한 코드 내역 (있다면)

 

function kboard_video_url_to_iframe($content){

       
    $content = preg_replace('/<a(.*)href=\"[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)">(.*)<\/a>/i', 'https://youtube.com/watch?v=$2', $content);
        $content = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/shorts\([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", '<iframe src="https://www.youtube.com/embed/$1" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>', $content);    
$content = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", '<iframe src="https://www.youtube.com/embed/$1" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>', $content);
    $content = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtu.be\/([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", '<iframe src="https://www.youtube.com/embed/$1" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>', $content);

좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
  • 너무너무 감사합니다 ^^ 덕분에 잘 수정되었어요!

  • 안녕하세요~^^

    아래 코드를 사용 해보시겠어요?

    /kboard/helper/Functions.helper.php 파일을 편집하시면 되겠습니다.

    ​/**
     * 유튜브, 비메오 동영상 URL을 iframe 코드로 변환한다.
     * @param string $content
     * @return mixed
     */
    function kboard_video_url_to_iframe($content){
    	// 유튜브
    	$content = preg_replace('/<a(.*)href=\"[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)">(.*)<\/a>/i', 'https://youtube.com/watch?v=$2', $content);
    	$content = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", '<iframe src="https://www.youtube.com/embed/$1" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>', $content);
    	$content = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtu.be\/([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", '<iframe src="https://www.youtube.com/embed/$1" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>', $content);
    	
    	// 유튜브 쇼츠
    	$content = preg_replace('/<a(.*)href=\"[a-zA-Z\/\/:\.]*youtube\.com\/shorts\/([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)">(.*)<\/a>/i', 'https://youtube.com/shorts/$2', $content);
    	$content = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube\.com\/shorts\/([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", '<iframe src="https://www.youtube.com/embed/$1" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>', $content);
    	
    	// 비메오
    	$content = preg_replace('/<a(.*)href=\"[a-zA-Z\/\/:\.]*vimeo.com\/(\d+)">(.*)<\/a>/i', 'https://vimeo.com/$2', $content);
    	$content = preg_replace("/\s*[a-zA-Z\/\/:\.]*vimeo.com\/(\d+)/i", '<iframe src="https://player.vimeo.com/video/$1" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>', $content);
    	
    	return $content;
    }

    감사합니다.

  • function kboard_video_url_to_iframe($content){
        // 유튜브

        $content = preg_replace('/<a(.*)href=\"[a-zA-Z\/\/:\.]*youtube.com\/shorts/\([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)">(.*)<\/a>/i', 'https://youtube.com/shorts/$2', $content);
    $content = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/shorts/\([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", 'https://youtube.com/watch?v=$1', $content);
    $content = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", '<iframe src="https://www.youtube.com/embed/$1" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>', $content);
     

     

    인터넷을 검색해보니 shorts 부분을 지우고 watch?v=$로 입력하면 등록이 되는것을 알게됐습니다. 

    그래서 이렇게 수정해봤는데 안돼네요 ^^;; preg_replace를 이용해서 

    shorts/ 를 /watch?v= 으로 변경하고 싶은데

    어떻게 수정하면 좋을까요?

  • AI에 의해 자동 생성된 답변이에요 😀

    안녕하세요! WordPress 전문가로서 여러분의 문제를 해결해 드릴 수 있습니다. 유튜브 쇼츠를 아이프레임으로 삽입하고 싶으시다면, 해당 기능을 제대로 구현하기 위해 정확한 함수를 사용해야 합니다. 현재 사용하고 계신 함수에는 몇 가지 오류가 있어 보입니다. 정규식 패턴이 제대로 작동하지 않거나, 아이프레임 코드를 삽입하는 부분에 문제가 있을 수 있습니다.

    문제를 해결하기 위해선 정확한 유튜브 쇼츠 URL을 인식하고, 해당 URL을 아이프레임 코드로 변환하는 함수를 작성해야 합니다. 정규식 패턴을 수정하거나, 아이프레임 코드를 삽입하는 부분을 다시 확인해 보세요. 또한, WordPress에서는 플러그인을 활용하여 유튜브 동영상을 쉽게 삽입할 수도 있습니다.

    더 자세한 도움이 필요하시다면, 다시 문의 주시면 성심 성의껏 도와드리겠습니다. 감사합니다!

    ↓ 아래 버튼을 눌러서 피드백해주세요.

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요