Advertisement
AMEEKER

Custom Excerpts w/Custom Fields, Per CPT, Genesis

Aug 23rd, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. remove_action( 'genesis_post_content', 'custom_excerpt' );
  2. add_action( 'genesis_post_content', 'custom_excerpt' );
  3. function custom_excerpt() {
  4.     // Return if CPT Hotels
  5.     if ( is_post_type_archive( 'hotels' ) )
  6.     // Store the address data
  7.     $address_data = array(
  8.         'address_1' => get_field( 'Address_1' ),
  9.         'address_2' => get_field( 'street_address_2' ),
  10.         'po_box'    => get_field( 'po_box' ),
  11.         'city'      => get_field( 'city' ),
  12.         'state'     => get_field( 'state' ),
  13.         'zip'       => get_field( 'zip' ),
  14.     );
  15. if ( '' != $address_data ) {
  16.         $address_data = strip_shortcodes( $text );
  17.         $address_data = apply_filters('the_content', $text);
  18.         $allowed_tags = '<p>,<a>,<em>,<strong>,<img>';
  19.         $address_data = strip_tags($text, $allowed_tags);
  20.         $address_data = str_replace(']]>', ']]>', $text);
  21.         $excerpt_length = 40; // 20 words
  22.         $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
  23.         $address_data = wp_trim_words( $text, $excerpt_length, $excerpt_more );
  24.     }
  25.     return apply_filters('the_excerpt', $text);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement