__( 'Primary Navigation', 'bootcms' ), ) ); // Add language support load_theme_textdomain( 'bootcms', get_template_directory() . '/languages' ); } add_action( 'after_setup_theme', 'bootcms_setup' ); /* Document title */ function bootcms_document_title_parts( $title ) { unset( $title['tagline'] ); return array( 'site' => get_bloginfo( 'name' ), 'title' => get_the_title(), ); return $title; } add_filter( 'document_title_parts', 'bootcms_document_title_parts' ); /* Document title separator */ function bootcms_document_title_separator( $separator ) { return '|'; } add_filter( 'document_title_separator', 'bootcms_document_title_separator' ); /* * Enqueue JS Scripts */ function bootcms_enqueue_js_scripts() { $bootcms_js_dependencies = array(); if ( get_theme_mod( 'bootcms_enable_jquery', false ) ) { wp_enqueue_script( 'jquery',); $bootcms_js_dependencies[] = 'jquery'; } if ( get_theme_mod( 'bootcms_enable_react', false ) ) { wp_enqueue_script( 'wp-element' ); wp_enqueue_script( 'frontend-react-app', get_template_directory_uri() . '/js/react-app.js', array( 'wp-element' ), null, true ); $bootcms_js_dependencies[] = 'frontend-react-app'; } if ( get_theme_mod( 'bootcms_enable_vue', false ) ) { wp_enqueue_script( 'bootcms-vue', get_template_directory_uri() . '/frameworks/vue/3.5.43/vue.global.prod.js', array(), null, true ); wp_enqueue_script( 'frontend-vue-app', get_template_directory_uri() . '/js/vue-app.js', array( 'bootcms-vue' ), null, true ); $bootcms_js_dependencies[] = 'frontend-vue-app'; } wp_enqueue_script( 'bootcms-template', get_template_directory_uri() . '/js/script.js', $bootcms_js_dependencies, null, true ); /** * Enqueue Frameworks **/ $bootcms_css_framework = get_theme_mod( 'bootcms_css_framework', 'bootcms' ); // BootCMS if ( $bootcms_css_framework === 'bootcms' ) { wp_enqueue_style( 'bootcms-bootcms', get_template_directory_uri() . '/frameworks/bootcms/2.0/bootcms.css', array(), '2.0' ); } // Bootstrap if ( $bootcms_css_framework === 'bootstrap' ) { $bootstrap_version = get_theme_mod( 'bootcms_bootstrap_version', '5.3.8' ); wp_enqueue_style( 'bootcms-bootstrap', get_template_directory_uri() . '/frameworks/bootstrap/' . $bootstrap_version . '/bootstrap.min.css', array(), $bootstrap_version ); // Bootstrap 5.3.8 RTL if ( $bootstrap_version === '5.3.8' ) { wp_enqueue_style( 'bootcms-bootstrap-rtl', get_template_directory_uri() . '/frameworks/bootstrap/5.3.8/bootstrap.rtl.min.css', array( 'bootcms-bootstrap' ), $bootstrap_version ); } $bootstrap_js_dependencies = array(); if ( version_compare( $bootstrap_version, '5.0.0', '<' ) ) { wp_enqueue_script( 'jquery' ); $bootstrap_js_dependencies[] = 'jquery'; // Bootstrap 4 Navwalker require_once get_template_directory() . '/inc/class-wp-bootstrap-navwalker.php'; } wp_enqueue_script( 'bootcms-bootstrap', get_template_directory_uri() . '/frameworks/bootstrap/' . $bootstrap_version . '/bootstrap.bundle.min.js', $bootstrap_js_dependencies, $bootstrap_version, true ); } // Bootwatch if ( $bootcms_css_framework === 'bootswatch' ) { $bootswatch_theme = get_theme_mod( 'bootcms_bootswatch_theme', 'slate' ); wp_enqueue_style( 'bootcms-bootswatch', get_template_directory_uri() . '/frameworks/bootswatch/' . $bootswatch_theme . '.min.css', array(), '5.3.8' ); wp_enqueue_script( 'bootcms-bootstrap', get_template_directory_uri() . '/frameworks/bootstrap/5.3.8/bootstrap.bundle.min.js', array(), '5.3.8', true ); } // Foundation if ( $bootcms_css_framework === 'foundation' ) { $foundation_version = get_theme_mod( 'bootcms_foundation_version', '6.9.0' ); wp_enqueue_style( 'bootcms-foundation', get_template_directory_uri() . '/frameworks/foundation/' . $foundation_version . '/foundation.min.css', array(), $foundation_version ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'bootcms-foundation', get_template_directory_uri() . '/frameworks/foundation/' . $foundation_version . '/foundation.min.js', array( 'jquery' ), $foundation_version, true ); wp_add_inline_script( 'bootcms-foundation', 'jQuery(function($) { $(document).foundation(); });' ); } // Bulma if ( $bootcms_css_framework === 'bulma' ) { wp_enqueue_style( 'bootcms-bulma', get_template_directory_uri() . '/frameworks/bulma/1.0.4/bulma.min.css', array(), '1.0.4' ); } } add_action( 'wp_enqueue_scripts', 'bootcms_enqueue_js_scripts' ); /* * Enqueue Styles */ function bootcms_enqueue_styles() { wp_enqueue_style('bootcms-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' )); if ( is_rtl() ) { wp_enqueue_style( 'bootcms-rtl', get_template_directory_uri() . '/rtl.css', array( 'bootcms-style' ), wp_get_theme()->get( 'Version' ) ); } } add_action( 'wp_enqueue_scripts', 'bootcms_enqueue_styles' ); /* ----------------------- * Enable Widgets */ function bootcms_widgets_init() { register_sidebar( array( 'name' => __( 'Custom Header Sidebar', 'bootcms' ), 'id' => 'header-custom', 'description' => __( 'Fully Custom Header.', 'bootcms' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => __( 'Header Right Sidebar', 'bootcms' ), 'id' => 'header-sidebar', 'description' => __( 'Optional widget area in the header (right).', 'bootcms' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => __( 'Customised Nav Menu', 'bootcms' ), 'id' => 'customised_nav_menu', 'description' => __( 'Add a custom or framework navbar menu here. The nav tag already wraps this widget. If needed, add classes to the nav tag in the Simple Styles section of the Customizer.', 'bootcms' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => __( 'Homepage Hero Unit', 'bootcms' ), 'id' => 'hero-unit-sidebar', 'description' => __( 'Space on Homepage for promotional content or a key introduction to the site.', 'bootcms' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => __( 'Homepage Right Sidebar', 'bootcms' ), 'id' => 'home-right-sidebar', 'description' => __( 'Homepage\'s right sidebar for widgets.', 'bootcms' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => __( 'Pages Right Sidebar', 'bootcms' ), 'id' => 'pages-right-sidebar', 'description' => __( 'Pages right sidebar for widgets.', 'bootcms' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => __( 'Custom Footer Sidebar', 'bootcms' ), 'id' => 'footer-custom', 'description' => __( 'Fully Custom Footer.', 'bootcms' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '' ) ); register_sidebar( array( 'name' => __( 'Footer Left', 'bootcms' ), 'id' => 'footer-left', 'description' => __( 'Optional widget area on the left side of the footer.', 'bootcms' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '' ) ); register_sidebar( array( 'name' => __( 'Footer Main', 'bootcms' ), 'id' => 'footer-main', 'description' => __( 'Optional widget area in the middle of the footer.', 'bootcms' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '' ) ); register_sidebar( array( 'name' => __( 'Footer Sidebar', 'bootcms' ), 'id' => 'footer-sidebar', 'description' => __( 'Optional widget area on the right side of the footer.', 'bootcms' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '' ) ); } add_action( 'widgets_init', 'bootcms_widgets_init' ); /* Link to Back End Code ------------------------------- */ add_action( 'after_setup_theme', function() { if ( is_customize_preview() ) { require_once get_template_directory() . '/inc/back-end.php'; } } ); /* Link to large HTML editor and Help ------------------ */ require_once get_template_directory() . '/inc/bootcms-editor.php'; require_once get_template_directory() . '/bootcms-help/help.php'; // Apply the Excerpt Length from Customizer to WP add_filter( 'excerpt_length', function( $length ) { $excerpt_length = get_theme_mod( 'post_excerpt_length', 55 ); if ( $excerpt_length < 1 ) { $excerpt_length = 55; } return $excerpt_length; } ); /* BootCMS JS Script for Navbar Toggle */ function mytheme_mobile_nav_script() { ?> post_modified ); } if ( ! metadata_exists( 'post', $post_id, 'datePublished' ) ) { add_post_meta( $post_id, 'datePublished', $post->post_date_gmt ); } if ( ! metadata_exists( 'post', $post_id, 'author' ) ) { add_post_meta( $post_id, 'author', '' ); } if ( ! metadata_exists( 'post', $post_id, 'inLanguage' ) ) { add_post_meta( $post_id, 'inLanguage', '' ); } if ( ! metadata_exists( 'post', $post_id, 'keywords' ) ) { add_post_meta( $post_id, 'keywords', '' ); } if ( ! metadata_exists( 'post', $post_id, 'description' ) ) { add_post_meta( $post_id, 'description', '' ); } if ( $post->post_status !== 'auto-draft' && ! metadata_exists( 'post', $post_id, 'name' )) { add_post_meta( $post_id, 'name', $post->post_title ); } } add_action( 'save_post_page', 'bootcms_add_page_fields', 10, 3 ); /** * Disable WordPress Block Editor and block styles. */ if ( get_theme_mod( 'bootcms_disable_block_editor', false ) ) { // Remove global styles and block layouts from the front end function bootcms_disable_global_styles() { remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles'); remove_action('wp_footer', 'wp_enqueue_global_styles', 1); } add_action('init', 'bootcms_disable_global_styles'); // Dequeue the core Gutenberg block library styles function bootcms_dequeue_block_styles() { wp_dequeue_style('wp-block-library'); // WordPress core block styles wp_dequeue_style('wp-block-library-theme'); // WordPress core block theme styles wp_dequeue_style('global-styles'); // Inline global styles fallback wp_dequeue_style( 'wp-block-paragraph' ); } add_action('wp_enqueue_scripts', 'bootcms_dequeue_block_styles', 100); } /* // Prevent WordPress from rendering separate inline styles for core blocks add_filter( 'should_load_separate_core_block_assets', '__return_false', 99 ); */ // Remove function for emoji if ( get_theme_mod( 'bootcms_disable_emojis', false ) ) { add_action( 'init', function() { remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_action( 'admin_print_styles', 'print_emoji_styles' ); remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); remove_filter( 'wp_check_invalid_utf8', 'wp_staticize_emoji' ); } ); } /* ========================================================= Frameworks ========================================================= */ $franework_menu_option = get_theme_mod( 'bootcms_css_framework', 'bootcms' ); /* * Bootstrap Menu Filters */ if ($franework_menu_option === 'bootstrap' || $franework_menu_option === 'bootswatch') { // 1. Add '.nav-item' to the
  • tags, and '.dropdown' if it has children add_filter( 'nav_menu_css_class', 'bootstrap5_menu_li_classes', 10, 4 ); function bootstrap5_menu_li_classes( $classes, $item, $args, $depth ) { if ( isset( $args->theme_location ) && $args->theme_location === 'primary' ) { $classes[] = 'nav-item'; if ( in_array( 'menu-item-has-children', $classes ) ) { $classes[] = 'dropdown'; } } return $classes; } // 2. Add '.nav-link' or '.dropdown-toggle' attributes to the tags add_filter( 'nav_menu_link_attributes', 'bootstrap5_menu_anchor_attributes', 10, 4 ); function bootstrap5_menu_anchor_attributes( $atts, $item, $args, $depth ) { if ( isset( $args->theme_location ) && $args->theme_location === 'primary' ) { $atts['class'] = 'nav-link'; // If it's a dropdown toggle item if ( in_array( 'menu-item-has-children', $item->classes ) ) { $atts['class'] .= ' dropdown-toggle'; $atts['data-bs-toggle'] = 'dropdown'; $atts['aria-expanded'] = 'false'; } // Add active class to current page link if ( in_array( 'current-menu-item', $item->classes ) ) { $atts['class'] .= ' active'; } } return $atts; } // 3. Change the default '.sub-menu' class to Bootstrap's '.dropdown-menu' add_filter( 'nav_menu_submenu_css_class', 'bootstrap5_menu_sub_menu_class', 10, 3 ); function bootstrap5_menu_sub_menu_class( $classes, $args, $depth ) { if ( isset( $args->theme_location ) && $args->theme_location === 'primary' ) { $classes = array( 'dropdown-menu' ); $use_navtag_classes = get_theme_mod( 'nav_tag_classes', '' ); if ( preg_match( '/(?:^|\s)(bg-[\w-]+)/', $use_navtag_classes, $match ) ) { $classes[] = $match[1]; } } return $classes; } } /* * Foundation Menu Filters */ if ($franework_menu_option === 'foundation') { // 1. Add the site name at start add_filter( 'wp_nav_menu_items', 'bootcms_foundation_menu_item', 10, 2 ); function bootcms_foundation_menu_item( $items, $args ) { if ( isset( $args->theme_location ) && $args->theme_location === 'primary' ) { $items = '
  • ' . $items; } return $items; } // 2. Add 'is-dropdown-submenu-parent' to the
  • tags if they have children add_filter( 'nav_menu_css_class', 'foundation6_menu_li_classes', 10, 4 ); function foundation6_menu_li_classes( $classes, $item, $args, $depth ) { if ( isset( $args->theme_location ) && $args->theme_location === 'primary' ) { // If the item has a submenu, Foundation requires a specific parent indicator if ( in_array( 'menu-item-has-children', $classes ) ) { $classes[] = 'is-accordion-submenu-parent'; } /* Current page if ( in_array( 'current-menu-item', $classes ) ) { $classes[] = 'is-active'; }*/ } return $classes; } // 3. Format the tags (add active state if needed) add_filter( 'nav_menu_link_attributes', 'foundation6_menu_anchor_attributes', 10, 4 ); function foundation6_menu_anchor_attributes( $atts, $item, $args, $depth ) { if ( isset( $args->theme_location ) && $args->theme_location === 'primary' ) { // Add Foundation active styling for the current page link if ( in_array( 'current-menu-item', $item->classes ) ) { $atts['class'] = isset($atts['class']) ? $atts['class'] . ' is-active' : 'is-active'; } } return $atts; } // 4. Change the sub-menu