Lego2012
9/26/2016 - 10:11 PM

DWB Read More Customizer

DWB Read More Customizer

<?php>
//* Add read more to customize -code by junior atoms
add_action( 'customize_register', 'jr_register_read_more_customize' );
function jr_register_read_more_customize( $wp_customize ) {

  $wp_customize->add_section(
    'jr_read_more_section',
    array(
      'title'     => 'Read More',
      'priority'  => 200
    )
  );

  $wp_customize->add_setting(
    'jr_read_more_setting',
    array(
      'sanitize_callback'  => 'jr_sanitize_read_more_text',
      'transport'          => 'refresh'
    )
  );

  $wp_customize->add_control(
    'jr_read_more_setting',
    array(
      'section'  => 'jr_read_more_section',
      'label'    => 'Read More Text',
      'type'     => 'text'
    )
  );

}

//* Sanitize the customize read more text
function jr_sanitize_read_more_text( $input ) {

  return wp_kses_post( force_balance_tags( $input ) );

}

//* Filter the read more text
add_filter( 'excerpt_more', 'jr_customize_read_more' );
add_filter( 'get_the_content_more_link', 'jr_customize_read_more' );
add_filter( 'the_content_more_link', 'jr_customize_read_more' );

//* Get the custom read more text
function jr_customize_read_more() {

  $custom_read_more = get_theme_mod( 'jr_read_more_setting', 'Read More' );

  return '&nbsp;<a class="more-link" title="' . $custom_read_more . '" href="' . get_permalink() . '">' . $custom_read_more . '</a>';

}
//* End of read more function