WordPress 쇼트 코드 내에서 자동 서식 사용 안 함
코드를 그대로 두는 (원시) 쇼트 코드를 만드는 튜토리얼을 봤어요.
http://www.wprecipes.com/disable-wordpress-automatic-formatting-on-posts-using-a-shortcode
안타깝게도 이것은 한 번에 하나의 쇼트 코드에만 적용됩니다.그리고 그 이유는else
스테이트먼트는 통상의 필터를 바이패스 해, 함수의 방향을 호출합니다.자동 및 문자 변환 기능에 대한 다른 수정 사항은 무시됩니다.
1. 여러 쇼트코드를 일치시키고 2. 다른 필터를_content에 보존하는 방법이 있습니까?
@helgatheviking의 솔루션을 여러 웹 사이트에 구현한 결과, 다음 라인만 필요하다고 확신했습니다.
// Move wpautop filter to AFTER shortcode is processed
remove_filter('the_content', 'wpautop');
add_filter('the_content', 'wpautop', 99);
add_filter('the_content', 'shortcode_unautop', 100);
그 안에 넣어주세요.functions.php
파일 작성하면 됩니다.
Donal MacArthur에서 약간 수정된 parse_shortcode_content 함수를 결합함으로써 가능한 한 이 문제를 해결했습니다(원래는 수동으로 wpautop을 호출했습니다).제가 제거해놨어요.wpautop을 실행하도록 디폴트필터 순서를 변경함으로써 쇼트코드가 이미 처리된 후 이전이 아니라 훨씬 늦게 실행됩니다.
// Clean up WordPress shortcode sormatting - important for nested shortcodes
// Adjusted from http://donalmacarthur.com/articles/cleaning-up-wordpress-shortcode-formatting/
function parse_shortcode_content( $content ) {
/* Parse nested shortcodes and add formatting. */
$content = trim( do_shortcode( shortcode_unautop( $content ) ) );
/* Remove '' from the start of the string. */
if ( substr( $content, 0, 4 ) == '' )
$content = substr( $content, 4 );
/* Remove '' from the end of the string. */
if ( substr( $content, -3, 3 ) == '' )
$content = substr( $content, 0, -3 );
/* Remove any instances of ''. */
$content = str_replace( array( '<p></p>' ), '', $content );
$content = str_replace( array( '<p> </p>' ), '', $content );
return $content;
}
필터 이동
// Move wpautop filter to AFTER shortcode is processed
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop', 99);
add_filter( 'the_content', 'shortcode_unautop', 100 );
편집:
그parse_shortcode_content()
(필요한 경우) 기능은 불필요합니다.필터 순서를 조정하기만 하면 됩니다.
제 경우 - 이 솔루션은 사이드 쇼트 코드(리버라이더) 중 하나를 망가뜨렸습니다.
여기서 또 다른 솔루션을 찾았습니다.http://wordpress-hackers.1065353.n5.nabble.com/shortcode-unautop-tp42085p42086.html
즉, 다음과 같은 다른 필터를 사용합니다.
// Via http://www.wpexplorer.com/clean-up-wordpress-shortcode-formatting/
if ( !function_exists('wpex_fix_shortcodes') ) {
function wpex_fix_shortcodes($content){
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
$content = strtr($content, $array);
return $content;
}
add_filter('the_content', 'wpex_fix_shortcodes');
}
저는 잘 동작합니다.
제 답변은 이쪽에서 확인하세요.
쇼트코드 콘텐츠에서 wpautop 제거 / 버퍼링에서 공백 제거
이 기능을 사용하면 다음과 같이 원하는 수의 특정 쇼트코드에 대해 wpautop을 끌 수 있습니다.
include "shortcode-wpautop-control.php";
chiedolabs_shortcode_wpautop_control(array('shortcodeone', 'shortcodetwo'));
언급URL : https://stackoverflow.com/questions/5940854/disable-automatic-formatting-inside-wordpress-shortcodes
'programing' 카테고리의 다른 글
Angular를 사용한 파일 업로드JS (0) | 2023.03.04 |
---|---|
클릭: 작동하지 않음 반응 js (0) | 2023.03.04 |
의존성 주입 용기의 이점은 무엇입니까? (0) | 2023.03.04 |
스프링 부트 핫 스왑 (0) | 2023.03.04 |
스프링 부트 응용 프로그램 시작 중 MethodArgumentNotValidException에 대해 매핑된 모호한 @ExceptionHandler 메서드를 얻는 중 (0) | 2023.03.04 |