Advertisement
alchymyth

custom excerpt read-more link

Jun 21st, 2012
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. // add a 'Custom Excerpt Link URL' field below post/page editor
  2. add_action('admin_menu', 'custom_excerpt_link');
  3. add_action('save_post', 'save_custom_excerpt_link');
  4. function custom_excerpt_link() {
  5. add_meta_box('custom_excerpt_link', 'Custom Excerpt Link URL <small>example: http://website.com - if left empty, the link will go to the full post</small>', 'custom_excerpt_link_input_function', 'post', 'normal', 'high');
  6. }
  7. function custom_excerpt_link_input_function() {
  8. global $post;
  9. echo '<input type="hidden" name="custom_excerpt_link_input_hidden" id="custom_excerpt_link_input_hidden" value="'.wp_create_nonce('custom_excerpt_link-nonce').'" />';
  10. echo '<input type="text" name="custom_excerpt_link_input" id="custom_excerpt_link_input" style="width:100%;" value="'.get_post_meta($post->ID,'excerpt_link',true).'" />';
  11. }
  12. function save_custom_excerpt_link($post_id) {
  13. if (!wp_verify_nonce($_POST['custom_excerpt_link_input_hidden'], 'custom_excerpt_link-nonce')) return $post_id;
  14. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
  15. $customMetaDesc = $_POST['custom_excerpt_link_input'];
  16. update_post_meta($post_id, 'excerpt_link', $customMetaDesc);
  17. }
  18.  
  19. //to use custom read-more link on excerpts//
  20. function excerpt_read_more_custom_link($output) {
  21.        global $post;
  22.        if( !($link = get_post_meta($post->ID,'excerpt_link',true)) ) $link = get_permalink($post->ID);
  23.        
  24.     return '<a href="'. esc_url($link) . '">' . ' [&hellip;&nbsp;Read&nbsp;All]' . '</a>';
  25. }
  26. add_filter('excerpt_more', 'excerpt_read_more_custom_link');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement