Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Register Nav Walker class_alias
- require_once('wp_bootstrap_navwalker.php');
- // Theme Support
- function syau_theme_setup () {
- // Add Featured Image Support
- add_theme_support('post-thumbnails');
- // Nav Menus
- register_nav_menus(array (
- 'primary' => __('Main Menu'),
- 'hamburger' => __('Mobile Menu'),
- 'footer' => __('Footer Menu')
- ));
- // Switch default core markup for search form, comment form, and comments to output valid HTML5
- add_theme_support( 'html5', array(
- 'search-form',
- 'comment-form',
- 'comment-list',
- 'gallery',
- 'caption',
- ) );
- //Enable support for Post Formats
- add_theme_support( 'post-formats', array(
- 'aside',
- 'image',
- 'video',
- 'quote',
- 'link',
- ) );
- // Set up the WordPress core custom background feature.
- add_theme_support( 'custom-background', apply_filters( 'darren_bachan_custom_background_args', array(
- 'default-color' => 'ffffff',
- 'default-image' => '',
- ) ) );
- }
- add_action('after_setup_theme', 'syau_theme_setup');
- //Add Our Widget Locations
- function ourWidgetsInit () {
- register_sidebar( array(
- 'name' => esc_html__( 'Sidebar', 'darren-bachan' ),
- 'id' => 'sidebar-1',
- 'description' => esc_html__( 'Add widgets here.', 'darren-bachan' ),
- 'before_widget' => '<section id="%1$s" class="widget %2$s">',
- 'after_widget' => '</section>',
- 'before_title' => '<h3 class="widget-title">',
- 'after_title' => '</h3>',
- ) );
- register_sidebar( array(
- 'name' => 'Footer Area 1',
- 'id' => 'footer1'
- ));
- }
- add_action('widgets_init', 'ourWidgetsInit');
- // Enqueue Scripts & Styles
- function syau_theme_scripts() {
- // Deregister the included library
- wp_deregister_script( 'jquery' );
- // Register the library again
- wp_register_script( 'jquery', get_template_directory_uri() . "/js/jquery-2.2.2.min.js", array(), '' , true );
- wp_enqueue_script('jquery');
- wp_enqueue_script( 'typed', get_template_directory_uri() . "/js/typed.min.js", array(), '' , true );
- wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . "/js/owl.carousel.min.js", array(), '' , true );
- wp_enqueue_script( 'bootstrap', get_template_directory_uri() . "/js/bootstrap.min.js", array(), '' , true );
- wp_enqueue_script( 'animation-scroll', get_template_directory_uri() . "/js/animatescroll.js", array(), '' , true );
- wp_enqueue_script( 'animation-slide', get_template_directory_uri() . "/js/animation-slide.js", array(), '' , true );
- wp_enqueue_script( 'main-js', get_template_directory_uri() . "/js/main.js", array(), '' , true );
- wp_enqueue_style( 'bootstrap', get_template_directory_uri()."/css/bootstrap.css", '', '' );
- wp_enqueue_style( 'fonts', get_template_directory_uri()."/css/fonts.css", '', '' );
- wp_enqueue_style( 'font-awesome', get_template_directory_uri()."/css/font-awesome.css", '', '' );
- wp_enqueue_style( 'flag-icon', get_template_directory_uri()."/css/flag-icon.css", '', '' );
- wp_enqueue_style( 'hamburger', get_template_directory_uri()."/css/hamburger.css", '', '' );
- wp_enqueue_style( 'owl-carousel', get_template_directory_uri()."/css/owl.carousel.css", '', '' );
- wp_enqueue_style( 'owl-theme', get_template_directory_uri()."/css/owl.theme.default.min.css", '', '' );
- wp_enqueue_style( 'main-css', get_template_directory_uri()."/style.css", '', '' );
- if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
- wp_enqueue_script( 'comment-reply' );
- }
- }
- add_action( 'wp_enqueue_scripts', 'syau_theme_scripts' );
- // Customizer File
- require get_template_directory(). '/inc/customizer.php';
- // Grab First Paragraph Of Text And Ignore Images For Excerpt
- function awesome_excerpt($text, $raw_excerpt) {
- if( ! $raw_excerpt ) {
- $content = apply_filters( 'the_content', get_the_content() );
- $text = substr( $content, 0, strpos( $content, '</p>' ) + 4 );
- }
- $text = preg_replace("/<img[^>]+\>/i", "", $text);
- return $text;
- }
- add_filter( 'wp_trim_excerpt', 'awesome_excerpt', 10, 2 );
- // Customize Excerpt Word Count Length
- 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;
- }
- // Empty <p> Fix On Images
- function filter_ptags_on_images($content){
- return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
- }
- add_filter('the_content', 'filter_ptags_on_images');
- // Change Author Permalinks
- function change_author_permalinks() {
- global $wp_rewrite;
- $wp_rewrite->author_base = 'member';
- $wp_rewrite->author_structure = '/' . $wp_rewrite->author_base. '/%author%';
- }
- add_action('init','change_author_permalinks');
- // Custom Comments Styling
- function mytheme_comment($comment, $args, $depth) {
- if ( 'div' === $args['style'] ) {
- $tag = 'div';
- $add_below = 'comment';
- } else {
- $tag = 'li';
- $add_below = 'div-comment';
- }
- ?>
- <<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
- <?php if ( 'div' != $args['style'] ) : ?>
- <div id="div-comment-<?php comment_ID() ?>" class="comment-meta-body">
- <?php endif; ?>
- <div class="comment-author vcard comment-meta-avatar">
- <?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment ); ?>
- </div>
- <div class="comment-meta-text">
- <div class="comment-meta-author">
- <?php printf( __( '<cite class="fn">%s</cite>' ), get_comment_author_link() ); ?>
- </div>
- <div class="comment-meta-time commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
- <?php
- /* translators: 1: date, 2: time */
- printf( __('%1$s @ %2$s'), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );
- ?>
- </div>
- <div class="comment-meta-mod">
- <?php if ( $comment->comment_approved == '0' ) : ?>
- <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
- <br />
- <?php endif; ?>
- </div>
- <div class="comment-content">
- <?php comment_text(); ?>
- <div class="reply">
- <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
- </div>
- </div>
- </div>
- <?php if ( 'div' != $args['style'] ) : ?>
- </div>
- <?php endif; ?>
- <?php
- }
- // Personalize Reply Link
- function add_comment_author_to_reply_link($link, $args, $comment){
- $comment = get_comment( $comment );
- // If no comment author is blank, use 'Anonymous'
- if ( empty($comment->comment_author) ) {
- if (!empty($comment->user_id)){
- $user=get_userdata($comment->user_id);
- $author=$user->user_login;
- } else {
- $author = __('Anonymous');
- }
- } else {
- $author = $comment->comment_author;
- }
- // If the user provided more than a first name, use only first name
- if(strpos($author, ' ')){
- $author = substr($author, 0, strpos($author, ' '));
- }
- // Replace Reply Link with "Reply to <Author First Name>"
- $reply_link_text = $args['reply_text'];
- //print_r($args);
- $link = str_replace($reply_link_text, 'Reply to ' . $author . ' <i class="fa fa-long-arrow-right"></i>', $link);
- return $link;
- }
- add_filter('comment_reply_link', 'add_comment_author_to_reply_link', 10, 3);
- //Personalize Cancel Reply Link
- function add_comment_author_to_cancel_reply_link($formatted_link, $link, $text){
- $comment = get_comment( $comment );
- // If no comment author is blank, use 'Anonymous'
- if ( empty($comment->comment_author) ) {
- if (!empty($comment->user_id)){
- $user=get_userdata($comment->user_id);
- $author=$user->user_login;
- } else {
- $author = __('Anonymous');
- }
- } else {
- $author = $comment->comment_author;
- }
- // If the user provided more than a first name, use only first name
- if(strpos($author, ' ')){
- $author = substr($author, 0, strpos($author, ' '));
- }
- // Replace "Cancel Reply" with "Cancel Reply to <author First Name>"
- $formatted_link = str_ireplace($text, 'Cancel reply to ' . $author . ' <i class="fa fa-long-arrow-right"></i>', $formatted_link);
- return $formatted_link;
- }
- add_filter('cancel_comment_reply_link', 'add_comment_author_to_cancel_reply_link', 10, 3);
- // Move comment field to bottom of comment form
- function wpb_move_comment_field_to_bottom( $fields ) {
- $comment_field = $fields['comment'];
- unset( $fields['comment'] );
- $fields['comment'] = $comment_field;
- return $fields;
- }
- // Remove website url field in comment form
- function remove_comment_fields($fields) {
- unset($fields['url']);
- return $fields;
- }
- add_filter('comment_form_default_fields','remove_comment_fields');
- add_filter( 'comment_form_fields', 'wpb_move_comment_field_to_bottom' );
- // Custom Page Pagination
- function wp_custom_pagination($args = [], $class = 'pagination') {
- if ($GLOBALS['wp_query']->max_num_pages <= 1) return;
- $args = wp_parse_args( $args, [
- 'mid_size' => 2,
- 'prev_next' => false,
- 'prev_text' => __('Older posts', 'textdomain'),
- 'next_text' => __('Newer posts', 'textdomain'),
- 'screen_reader_text' => __('Posts navigation', 'textdomain'),
- ]);
- $links = paginate_links($args);
- $next_link = get_previous_posts_link($args['next_text']);
- $prev_link = get_next_posts_link($args['prev_text']);
- $template = apply_filters( 'navigation_markup_template', '
- <nav class="navigation %1$s" role="navigation">
- <div class="nav-links">%3$s<div class="page-numbers-container">%4$s</div>%5$s</div>
- </nav>', $args, $class);
- echo sprintf($template, $class, $args['screen_reader_text'], $prev_link, $links, $next_link);
- }
- add_filter('previous_posts_link_attributes', function()
- {
- return 'class="next"';
- });
- add_filter('next_posts_link_attributes', function()
- {
- return 'class="prev"';
- });
- // [Title] Shortcode
- function shortcode_title($atts, $content = null) {
- $output = '';
- $output .= '<div class="page-header">';
- $output .= $content;
- $output .= '</div>';
- return $output;
- }
- add_shortcode('title','shortcode_title');
- function shortcode_container($atts, $content = null) {
- $type = isset($atts['type']) ? $atts['type'] : '';
- $margintop = isset($atts['margintop']) ? $atts['margintop'] : '';
- $marginbottom = isset($atts['marginbottom']) ? $atts['marginbottom'] : '';
- $output = '';
- $output .= '<div class="container '.$type.'" style="margin-top:'.$margintop.'; margin-bottom:'.$marginbottom.'">';
- $output .= '<section>';
- $output .= '<div class="row">';
- $output .= apply_filters('the_content', $content);
- $output .= '</div>';
- $output .= '</section>';
- $output .= '</div>';
- return $output;
- }
- add_shortcode('container','shortcode_container');
- function so_shortcode_row($atts, $content = null) {
- $type = isset($atts['type']) ? $atts['type'] : '';
- $margintop = isset($atts['margintop']) ? $atts['margintop'] : '';
- $marginbottom = isset($atts['marginbottom']) ? $atts['marginbottom'] : '';
- $output = '';
- $output .= '<div class="row '.$type.'" style="margin-top:'.$margintop.'; margin-bottom:'.$marginbottom.'">';
- $output .= '<div class="inner">';
- $output .= apply_filters('the_content', $content);
- $output .= '</div>';
- $output .= '</div>';
- return $output;
- }
- add_shortcode('row','so_shortcode_row');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement