Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * BASE FUNCTIONS
- * Add this line below to functions.php in your theme
- * include get_template_directory() . '/functions-base.php';
- */
- /**
- * Return the excerpt from acf field or custom field wordpress.
- */
- function acf_excerpt($text, $excerpt_length = 20) {
- if ( '' != $text ) {
- $text = strip_shortcodes( $text );
- $text = apply_filters('the_content', $text);
- $text = str_replace(']]>', ']]>', $text);
- $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
- $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
- }
- return apply_filters('the_excerpt', $text);
- }
- /**
- * Limit words the_excerpt from default content field wordpress
- */
- function excerpt($limit) {
- $excerpt = explode(' ', get_the_excerpt(), $limit);
- if (count($excerpt)>=$limit) {
- array_pop($excerpt);
- $excerpt = implode(" ",$excerpt).'...';
- } else {
- $excerpt = implode(" ",$excerpt);
- }
- $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
- return $excerpt;
- }
- /**
- * Hide page from other levels of users different than admin
- */
- function exclude_pages_from_admin($query) {
- if ( ! is_admin() )
- return $query;
- global $pagenow, $post_type;
- if ( !current_user_can( 'administrator' ) && $pagenow == 'edit.php' && $post_type == 'page' )
- $query->query_vars['post__not_in'] = array( ); // Enter your page IDs here
- }
- add_filter( 'parse_query', 'exclude_pages_from_admin' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement