Last active
August 29, 2015 14:04
-
-
Save gbyat/02366c64b1ae73b1a80e to your computer and use it in GitHub Desktop.
Typographic Quotes in WordPress
This file contains 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
/*********************************** | |
* use in your theme functions.php | |
* or wordpress plugin | |
* correct quotes in multilingual sites | |
* http://codex.wordpress.org/Quicktags_API | |
***********************************/ | |
function pptf_add_german_quotes() { | |
if (wp_script_is('quicktags')) { | |
?> | |
<script type="text/javascript"> | |
QTags.addButton( 'german_quotes', '„cite“', '„', '“', '', 'German Quotes', '' ); | |
QTags.addButton( 'french_quotes', '« cite »','« ', ' »', '', 'French Quotes', '' ); | |
QTags.addButton( 'italian_quotes', '«cite»','«', '»', '', 'Italian Quotes', '' ); | |
QTags.addButton( 'dechevron_quotes', '»cite«','»', '«', '', 'German Chevrons', '' ); | |
</script> | |
<?php } | |
} | |
add_action('admin_print_footer_scripts', 'pptf_add_german_quotes' ); | |
/*********************************** | |
* visual editor quotes buttons | |
***********************************/ | |
function pptf_add_mce_buttons() { | |
// check user permissions | |
if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) { | |
return; | |
} | |
// check if WYSIWYG is enabled | |
if ( 'true' == get_user_option( 'rich_editing' ) ) { | |
add_filter( 'mce_external_plugins', 'pptf_add_tinymce_plugins' ); | |
add_filter( 'mce_buttons', 'pptf_register_mce_button' ); | |
} | |
} | |
add_action('admin_head', 'pptf_add_mce_buttons'); | |
// Declare script for new button | |
function pptf_add_tinymce_plugins( $plugin_array ) { | |
$plugin_array['de_quotes_button'] = get_template_directory_uri() .'/js/ve_custom_buttons.js'; | |
$plugin_array['fr_quotes_button'] = get_template_directory_uri() .'/js/ve_custom_buttons.js'; | |
$plugin_array['it_quotes_button'] = get_template_directory_uri() .'/js/ve_custom_buttons.js'; | |
$plugin_array['de_chevron_button'] = get_template_directory_uri() .'/js/ve_custom_buttons.js'; | |
return $plugin_array; | |
} | |
// Register new button in the editor | |
function pptf_register_mce_button( $buttons ) { | |
array_push( $buttons, 'de_quotes_button' ); | |
array_push( $buttons, 'fr_quotes_button' ); | |
array_push( $buttons, 'it_quotes_button' ); | |
array_push( $buttons, 'de_chevron_button' ); | |
return $buttons; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment