Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <?php
  2. /**
  3. * BASE FUNCTIONS
  4. * Add this line below to functions.php in your theme
  5. * include get_template_directory() . '/functions-base.php';
  6. */
  7.  
  8. /**
  9. * Return the excerpt from acf field or custom field wordpress.
  10. */
  11. function acf_excerpt($text, $excerpt_length = 20) {
  12. if ( '' != $text ) {
  13. $text = strip_shortcodes( $text );
  14. $text = apply_filters('the_content', $text);
  15. $text = str_replace(']]>', ']]>', $text);
  16. $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
  17. $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
  18. }
  19. return apply_filters('the_excerpt', $text);
  20. }
  21.  
  22. /**
  23. * Limit words the_excerpt from default content field wordpress
  24. */
  25. function excerpt($limit) {
  26. $excerpt = explode(' ', get_the_excerpt(), $limit);
  27. if (count($excerpt)>=$limit) {
  28. array_pop($excerpt);
  29. $excerpt = implode(" ",$excerpt).'...';
  30. } else {
  31. $excerpt = implode(" ",$excerpt);
  32. }
  33. $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
  34. return $excerpt;
  35. }
  36.  
  37. /**
  38. * Hide page from other levels of users different than admin
  39. */
  40. function exclude_pages_from_admin($query) {
  41. if ( ! is_admin() )
  42. return $query;
  43. global $pagenow, $post_type;
  44. if ( !current_user_can( 'administrator' ) && $pagenow == 'edit.php' && $post_type == 'page' )
  45. $query->query_vars['post__not_in'] = array( ); // Enter your page IDs here
  46. }
  47. add_filter( 'parse_query', 'exclude_pages_from_admin' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement