Reading Settings section. This value is used to specify the number of words that you would like to appear in the the_excerpt().
Author: Lee Kelleher
Version: 1.1
Author URI: http://leekelleher.com/
*/
function lk_excerpt_length_init() {
add_settings_field( 'lk-excerpt-length-field', 'Excerpt Length', 'lk_excerpt_length_field_callback_function', 'reading', 'default', array( 'label_for' => 'lk-excerpt-length-field' ) );
add_settings_field( 'lk-excerpt-suffix-field', 'Excerpt Suffix', 'lk_excerpt_suffix_field_callback_function', 'reading', 'default', array( 'label_for' => 'lk-excerpt-suffix-field' ) );
register_setting( 'reading', 'lk-excerpt-length-value', 'intval' );
register_setting( 'reading', 'lk-excerpt-suffix-value' );
}
function lk_excerpt_length_field_callback_function() {
$option_value = get_option( 'lk-excerpt-length-value', 55 );
if ( '' == $option_value || '0' == $option_value )
$option_value = 55; // the default value
echo "\n";
echo 'The number of words that you want to appear in the_excerpt()';
}
function lk_excerpt_suffix_field_callback_function() {
$option_value = get_option( 'lk-excerpt-suffix-value', '[...]' );
echo "\n";
echo 'Set the text to be used at the end of the excerpt. This replaces the default [...] text';
}
function lk_excerpt_length( $default_value ) {
$option_value = get_option( 'lk-excerpt-length-value' );
return ( '' != $option_value && '0' != $option_value ) ? $option_value : $default_value;
}
function lk_excerpt_suffix( $text ) {
$option_value = get_option( 'lk-excerpt-suffix-value', '[...]' );
return str_replace( '[...]', $option_value, $text );
}
function filter_plugin_meta($links, $file) {
if ( $file == plugin_basename( __FILE__ ) )
return array_merge( $links, array( sprintf( '%s', __('Settings') ) ) );
return $links;
}
add_action( 'admin_init', 'lk_excerpt_length_init' );
add_filter( 'excerpt_length', 'lk_excerpt_length' );
add_filter( 'get_the_excerpt', 'lk_excerpt_suffix' );
add_filter( 'plugin_row_meta', 'filter_plugin_meta', 10, 2 );
?>