Created
March 7, 2014 13:53
-
-
Save LaboratorioEfe5/9411870 to your computer and use it in GitHub Desktop.
Wordpress excerpt character count qtranslate compatible
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
/** | |
* excerpt char count | |
* qtranslate compatible | |
* just cut&paste in your functions.php | |
* author: http://somosf5.com | |
*/ | |
function excerpt_count_js(){ | |
$languajes=array('es'); | |
$languajeActual =''; | |
$excerptID='excerpt'; | |
$banderitasID=''; | |
if ( function_exists("qtrans_getSortedLanguages") ) { | |
$languajes=qtrans_getSortedLanguages(true); | |
$excerptID='qtrans_textarea_excerpt_'; | |
$banderitasID='qtrans_switcher_postexcerpt_'; | |
} | |
$salida= '<script>jQuery(document).ready(function(){ | |
jQuery("#postexcerpt .inside p").before("<div style=\"color:#666;\"><small>Excerpt length: </small><input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"excerpt_counter\" readonly=\"\" style=\"background:#fff;\"> <small>character(s).</small></div>");'; | |
foreach ($languajes as $key => $languajeActual) { | |
$idExcerptFinal = $excerptID; | |
if ($excerptID!=='excerpt'){ | |
$idExcerptFinal = $excerptID.$languajeActual; | |
$salida.=' | |
jQuery("#'.$banderitasID.$languajeActual.'").click( function() { | |
jQuery("#excerpt_counter").val(jQuery("#'.$idExcerptFinal.'").val().length); | |
}); | |
'; | |
} | |
$salida.='jQuery("#excerpt_counter").val(jQuery("#'.$idExcerptFinal.'").val().length); | |
jQuery("#'.$idExcerptFinal.'").keyup( function() { | |
jQuery("#excerpt_counter").val(jQuery("#'.$idExcerptFinal.'").val().length); | |
});'; | |
} | |
$salida.='});</script>'; | |
echo $salida; | |
} | |
add_action( 'admin_head-post.php', 'excerpt_count_js'); | |
add_action( 'admin_head-post-new.php', 'excerpt_count_js'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment