Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // add a 'Custom Excerpt Link URL' field below post/page editor
- add_action('admin_menu', 'custom_excerpt_link');
- add_action('save_post', 'save_custom_excerpt_link');
- function custom_excerpt_link() {
- 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');
- }
- function custom_excerpt_link_input_function() {
- global $post;
- echo '<input type="hidden" name="custom_excerpt_link_input_hidden" id="custom_excerpt_link_input_hidden" value="'.wp_create_nonce('custom_excerpt_link-nonce').'" />';
- 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).'" />';
- }
- function save_custom_excerpt_link($post_id) {
- if (!wp_verify_nonce($_POST['custom_excerpt_link_input_hidden'], 'custom_excerpt_link-nonce')) return $post_id;
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
- $customMetaDesc = $_POST['custom_excerpt_link_input'];
- update_post_meta($post_id, 'excerpt_link', $customMetaDesc);
- }
- //to use custom read-more link on excerpts//
- function excerpt_read_more_custom_link($output) {
- global $post;
- if( !($link = get_post_meta($post->ID,'excerpt_link',true)) ) $link = get_permalink($post->ID);
- return '<a href="'. esc_url($link) . '">' . ' [… Read All]' . '</a>';
- }
- add_filter('excerpt_more', 'excerpt_read_more_custom_link');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement