Skip to content

Instantly share code, notes, and snippets.

@cbeltr2020
Created March 26, 2020 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbeltr2020/906f76b249a575f8578de2b67690a6ce to your computer and use it in GitHub Desktop.
Save cbeltr2020/906f76b249a575f8578de2b67690a6ce to your computer and use it in GitHub Desktop.
wordpress Functions.php
<?php
/**
* Functions.php contains all the core functions for your theme to work properly.
* Please do not edit this file!!
*
* @since 1.0
*/
// Theme info
function wpex_get_theme_info( $return = 'array' ) {
$array = array(
'name' => 'Fresh &amp; Clean',
'dir' => get_template_directory_uri() .'/functions/',
'url' => 'http://www.wpexplorer.com/fresh-clean-wordpress-theme-by-wpexplorer/',
'changelog' => 'http://www.wpexplorer.com/changelogs/fresh-clean/',
);
if ( 'array' == $return ) {
return $array;
} else {
return $array[$return];
}
}
// Include admin options
require_once( get_template_directory() .'/functions/options.php' );
// Theme setup
function wpex_setup() {
// Default content width
global $content_width;
$content_width = 645;
// Theme support
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'custom-background' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'title-tag' );
// Register navigation menus
register_nav_menus ( array(
'main_menu' => __( 'Main', 'fresh-clean' )
) );
// Localize
load_theme_textdomain( 'fresh-clean', get_template_directory() .'/languages' );
// Image sizes
add_image_size( 'wpex_slide', '1000', '400', true );
add_image_size( 'wpex_entry', '200', '150', true );
add_image_size( 'wpex_post', '768', 9999, false );
}
add_action( 'after_setup_theme', 'wpex_setup' );
// Load CSS and JS
require_once( get_template_directory() . '/functions/scripts.php' );
// Social functions
require_once( get_template_directory() . '/functions/social.php' );
// Custom Widgets
require_once( get_template_directory() . '/functions/widgets/widget-areas.php' );
require_once( get_template_directory() . '/functions/widgets/widget-post-thumbs.php' );
// Slides post type
require_once( get_template_directory() . '/functions/post-types/slides.php' );
// Admin only functions
if ( is_admin() ) {
require_once( get_template_directory() . '/functions/updates.php' );
require_once( get_template_directory() . '/functions/meta/meta-slides.php' );
if ( ! defined( 'WPEX_DISABLE_THEME_ABOUT_PAGE' ) ) {
require_once( get_template_directory() . '/functions/welcome.php' );
}
if ( ! defined( 'WPEX_DISABLE_THEME_DASHBOARD_FEEDS' ) ) {
require_once( get_template_directory() . '/functions/dashboard-feed.php' );
}
}
// Front-end functions
else {
require_once( get_template_directory() . '/functions/hooks.php' );
}
// Change default read more style
function wpex_new_excerpt_more( $more ) {
global $post;
return '...';
}
add_filter( 'excerpt_more', 'wpex_new_excerpt_more' );
// Change default excerpt length
function wpex_custom_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'wpex_custom_excerpt_length', 999 );
// Custom menu walker
class WPEX_Dropdown_Walker_Nav_Menu extends Walker_Nav_Menu {
function display_element($element, &$children_elements, $max_depth, $depth=0, $args, &$output) {
$id_field = $this->db_fields['id'];
if ( !empty( $children_elements[$element->$id_field] ) && ( $depth == 0 ) ) {
$element->classes[] = 'dropdown';
$element->title .= ' <i class="fa fa-angle-down"></i>';
}
if ( !empty( $children_elements[$element->$id_field] ) && ( $depth > 0 ) ) {
$element->classes[] = 'dropdown';
$element->title .= ' <i class="fa fa-angle-right"></i>';
}
Walker_Nav_Menu::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
}
}
// Custom comments output
function wpex_comments_callback( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>" class="comment-body <?php if ($comment->comment_approved == '0' ) echo 'pending-comment'; ?> clearfix">
<div class="comment-details">
<div class="comment-avatar">
<?php echo get_avatar($comment, $size = '45' ); ?>
</div><!-- /comment-avatar -->
<div class="comment-meta">
<section class="comment-author vcard">
<?php printf(__( '<cite class="author">%s</cite>' ), get_comment_author_link()) ?>
</section><!-- /comment-meta -->
<span class="comment-date"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php echo get_comment_date( 'l j F Y, g:i a' ); ?></a></span>
</div>
<section class="comment-content">
<div class="comment-text">
<?php comment_text() ?>
</div><!-- /comment-text -->
<?php
// Show reply link if threaded comments are enabled
if ( get_option( 'thread_comments' ) == 1 ) { ?>
<div class="comment-reply">
<span class="icon-reply"></span>
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply','fresh-clean' ),'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ) ?>
</div>
<?php } ?>
</section><!-- /comment-content -->
</div><!-- /comment-details -->
</div><!-- /comment -->
<?php
}
// Pagination
if ( ! function_exists( 'wpex_pagination' ) ) {
function wpex_pagination() {
global $wp_query;
$total = $wp_query->max_num_pages;
$big = 999999999; // need an unlikely integer
if ( $total > 1 ) {
if ( ! $current_page = get_query_var( 'paged' ) ) {
$current_page = 1;
}
if ( get_option( 'permalink_structure' ) ) {
$format = 'page/%#%/';
} else {
$format = '&paged=%#%';
}
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => $format,
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $total,
'mid_size' => 3,
'type' => 'list',
'prev_text' => '&laquo;',
'next_text' => '&raquo;',
));
}
}
}
// Re-locate comment form fields
if ( apply_filters( 'wpex_move_comment_form_fields', true ) ) {
function wpex_move_comment_form_fields( $fields ) {
$comment_field = $fields['comment'];
unset( $fields['comment'] );
$fields['comment'] = $comment_field;
return $fields;
}
add_filter( 'comment_form_fields', 'wpex_move_comment_form_fields' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment