Created
September 8, 2020 11:18
-
-
Save miladoll/aba99274d218a40ac5069c3c6967dcd2 to your computer and use it in GitHub Desktop.
WordPressの余計なwptexturizeは元から絶たなきゃダメ!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
WordPressの wptexturize とか wpautop とか呼ばれる機能停止して | |
ダブルクオートとかダッシュとかの自動変換を止めるねん | |
Gutenbergにも対応する版 | |
*/ | |
call_user_func( function() { | |
add_filter( 'run_wptexturize', '__return_false', PHP_INT_MAX ); | |
// 勝手に改行を <p></p> にしたりするのを止める | |
add_action('init', function() { | |
remove_filter('the_title', 'wpautop'); | |
remove_filter('the_title', 'wptexturize'); | |
remove_filter('the_content', 'wpautop'); | |
remove_filter('the_content', 'wptexturize'); | |
remove_filter('the_excerpt', 'wpautop'); | |
remove_filter('the_excerpt', 'wptexturize'); | |
remove_filter('the_editor_content', 'wp_richedit_pre'); | |
}); | |
add_filter('tiny_mce_before_init', function($init) { | |
// @see http://wpcj.net/727 | |
$init['wpautop'] = false; | |
// $init['apply_source_formatting'] = false; | |
return $init; | |
}); | |
// でも&はエスケープしたいねん | |
$replace_amp = function ( $content ) { | |
return( preg_replace( '/&(?![^&;]{1,10};)/', '&', $content ) ); | |
}; | |
add_filter( | |
'the_content', | |
function( $content ) use ( $replace_amp ) { | |
return( $replace_amp( $content ) ); | |
} | |
); | |
add_filter( | |
'the_excerpt', | |
function( $content ) use ( $replace_amp ) { | |
return( $replace_amp( $content ) ); | |
} | |
); | |
add_filter( | |
'the_title', | |
function( $content ) use ( $replace_amp ) { | |
return( $replace_amp( $content ) ); | |
} | |
); | |
add_filter( | |
'comment_text', | |
function( $content ) use ( $replace_amp ) { | |
return( $replace_amp( $content ) ); | |
} | |
); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment