Created
June 20, 2013 21:30
-
-
Save mjangda/5826826 to your computer and use it in GitHub Desktop.
Update kses and TinyMCE to allow select data-* attributes 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
<?php | |
add_action( 'after_setup_theme', 'x_kses_allow_data_attributes_on_links' ); | |
function x_kses_allow_data_attributes_on_links() { | |
global $allowedposttags; | |
$tags = array( 'a' ); | |
$new_attributes = array( | |
'data-foo' => array(), | |
'data-bar' => array(), | |
); | |
foreach ( $tags as $tag ) { | |
if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) | |
$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); | |
} | |
} | |
add_filter( 'tiny_mce_before_init', 'x_tinymce_allow_data_attributes_on_links' ); | |
function x_tinymce_allow_data_attributes_on_links( $options ) { | |
if ( ! isset( $options['extended_valid_elements'] ) ) | |
$options['extended_valid_elements'] = ''; | |
$options['extended_valid_elements'] .= ',a[data-foo|data-bar|class|id|style|href]'; | |
return $options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment