esc_html__( 'Primary Menu', 'stackwise' ), 'footer' => esc_html__( 'Footer Menu', 'stackwise' ), ) ); /* * 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', 'style', 'script', ) ); // Set up the WordPress core custom background feature. add_theme_support( 'custom-background', apply_filters( 'stackwise_custom_background_args', array( 'default-color' => '0d1117', 'default-image' => '', ) ) ); // Add theme support for selective refresh for widgets. add_theme_support( 'customize-selective-refresh-widgets' ); // Add support for custom logo. add_theme_support( 'custom-logo', array( 'height' => 80, 'width' => 200, 'flex-width' => true, 'flex-height' => true, ) ); // Add support for Block Styles. add_theme_support( 'wp-block-styles' ); // Add support for full and wide align images. add_theme_support( 'align-wide' ); // Add support for editor styles. add_theme_support( 'editor-styles' ); // Enqueue editor styles. add_editor_style( 'assets/css/editor-style.css' ); // Add support for responsive embedded content. add_theme_support( 'responsive-embeds' ); // Add support for custom line height controls. add_theme_support( 'custom-line-height' ); // Add support for experimental link color control. add_theme_support( 'link-color' ); // Add support for custom units. add_theme_support( 'custom-units' ); // Add support for custom spacing. add_theme_support( 'custom-spacing' ); // Remove core block patterns. remove_theme_support( 'core-block-patterns' ); // Add support for appearance tools. add_theme_support( 'appearance-tools' ); // Add support for custom header image. add_theme_support( 'custom-header', apply_filters( 'stackwise_custom_header_args', array( 'default-image' => '', 'header-text' => false, 'width' => 1200, 'height' => 900, 'flex-height' => true, 'flex-width' => true, ) ) ); /** * Add support for Starter Content */ add_theme_support( 'starter-content', stackwise_get_starter_content() ); } add_action( 'after_setup_theme', 'stackwise_setup' ); /** * Set the content width in pixels, based on the theme's design and stylesheet. * * @global int $content_width */ function stackwise_content_width() { $GLOBALS['content_width'] = apply_filters( 'stackwise_content_width', 1200 ); } add_action( 'after_setup_theme', 'stackwise_content_width', 0 ); /** * Register widget area. */ function stackwise_widgets_init() { register_sidebar( array( 'name' => esc_html__( 'Footer Widget Area', 'stackwise' ), 'id' => 'footer-1', 'description' => esc_html__( 'Add footer widgets here.', 'stackwise' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'stackwise_widgets_init' ); /** * Enqueue scripts and styles. */ function stackwise_scripts() { // Enqueue Google Fonts. wp_enqueue_style( 'stackwise-google-fonts', stackwise_google_fonts_url(), array(), STACKWISE_VERSION ); // Main stylesheet. wp_enqueue_style( 'stackwise-style', get_stylesheet_uri(), array(), STACKWISE_VERSION ); // Add inline styles from customizer. wp_add_inline_style( 'stackwise-style', stackwise_get_customizer_css() ); // Navigation script. wp_enqueue_script( 'stackwise-navigation', STACKWISE_URI . '/assets/js/navigation.js', array(), STACKWISE_VERSION, true ); // Theme toggle script. wp_enqueue_script( 'stackwise-theme-toggle', STACKWISE_URI . '/assets/js/theme-toggle.js', array(), STACKWISE_VERSION, true ); // Fallback labels for the toggle button, used if its data attributes are missing. wp_localize_script( 'stackwise-theme-toggle', 'stackwiseToggle', array( 'labelDark' => __( 'Switch to dark mode', 'stackwise' ), 'labelLight' => __( 'Switch to light mode', 'stackwise' ), ) ); // Typing effect (only on front page). if ( is_front_page() ) { wp_enqueue_script( 'stackwise-typing-effect', STACKWISE_URI . '/assets/js/typing-effect.js', array(), STACKWISE_VERSION, true ); // Pass data to typing effect script. wp_localize_script( 'stackwise-typing-effect', 'stackwiseTyping', array( 'strings' => stackwise_get_typing_strings(), ) ); } // Comment reply script. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } } add_action( 'wp_enqueue_scripts', 'stackwise_scripts' ); /** * Apply the saved or system light mode before the first paint. * * The theme-toggle.js script loads in the footer, so without this script visitors * who chose light mode would briefly see the dark default. The script is a * fixed string and contains no user data. */ function stackwise_print_theme_mode_script() { wp_print_inline_script_tag( "(function(){try{var t=localStorage.getItem('stackwise-theme');if('light'===t||(!t&&window.matchMedia&&window.matchMedia('(prefers-color-scheme: light)').matches)){document.documentElement.setAttribute('data-theme','light');}}catch(e){}}());" ); } add_action( 'wp_head', 'stackwise_print_theme_mode_script', 1 ); /** * Get Google Fonts URL * * @return string Google Fonts URL */ function stackwise_google_fonts_url() { $fonts_url = ''; $fonts = array(); $subsets = 'latin,latin-ext'; // Inter font. $fonts[] = 'Inter:wght@400;500;600;700'; // JetBrains Mono font. $fonts[] = 'JetBrains+Mono:wght@400;500;600;700'; if ( $fonts ) { $fonts_url = 'https://fonts.googleapis.com/css2?family=' . implode( '&family=', $fonts ) . '&display=swap'; } return esc_url_raw( $fonts_url ); } /** * Default lines for the hero typing effect, one per line. * * @return string Translated default lines separated by new lines. */ function stackwise_get_default_typing_text() { return implode( "\n", array( __( 'Full Stack Developer', 'stackwise' ), __( 'Frontend Engineer', 'stackwise' ), __( 'Backend Developer', 'stackwise' ), __( 'UI/UX Enthusiast', 'stackwise' ), ) ); } /** * Get typing effect strings from customizer * * @return array Array of strings for typing effect */ function stackwise_get_typing_strings() { $strings = get_theme_mod( 'stackwise_hero_typing_text', stackwise_get_default_typing_text() ); return array_map( 'trim', explode( "\n", $strings ) ); } /** * Get customizer CSS * * @return string CSS from customizer options */ function stackwise_get_customizer_css() { $css = ''; // Accent color. $accent_color = get_theme_mod( 'stackwise_accent_color', '#58a6ff' ); if ( '#58a6ff' !== $accent_color ) { $css .= ':root { --sw-color-accent: ' . esc_attr( $accent_color ) . '; }'; } return $css; } /** * Starter content for new sites. * * Shown in the Customizer preview on a fresh site and created only when the * user publishes the Customizer. It sets up the pages, front page sections, * menus and footer widgets so the theme looks complete from the start. * * @return array Starter content definition. */ function stackwise_get_starter_content() { $paragraph = static function ( $text ) { return '

' . esc_html( $text ) . '

'; }; return array( 'posts' => array( 'home' => array( 'post_type' => 'page', 'post_title' => _x( 'Home', 'Theme starter content', 'stackwise' ), 'post_content' => '', ), 'about' => array( 'post_type' => 'page', 'post_title' => _x( 'About Me', 'Theme starter content', 'stackwise' ), 'post_content' => $paragraph( _x( 'I am a developer who builds fast, accessible websites. Use this page to tell visitors who you are, what you work on and what you care about.', 'Theme starter content', 'stackwise' ) ) . $paragraph( _x( 'Add a featured image to this page to show a photo next to this text on the front page.', 'Theme starter content', 'stackwise' ) ), ), 'services' => array( 'post_type' => 'page', 'post_title' => _x( 'What I Do', 'Theme starter content', 'stackwise' ), 'post_content' => stackwise_pattern_skills_columns(), ), 'blog' => array( 'post_type' => 'page', 'post_title' => _x( 'Blog', 'Theme starter content', 'stackwise' ), ), 'contact' => array( 'post_type' => 'page', 'post_title' => _x( 'Contact', 'Theme starter content', 'stackwise' ), 'template' => 'template-contact.php', 'post_content' => $paragraph( _x( 'Have a project in mind or just want to say hello? Add a contact form block from your form plugin here, and set your email address and location in Appearance > Customize > Theme Options.', 'Theme starter content', 'stackwise' ) ), ), ), 'options' => array( 'show_on_front' => 'page', 'page_on_front' => '{{home}}', 'page_for_posts' => '{{blog}}', ), 'theme_mods' => array( 'stackwise_fp_about_page' => '{{about}}', 'stackwise_fp_services_page' => '{{services}}', 'stackwise_fp_contact_page' => '{{contact}}', ), 'widgets' => array( 'footer-1' => array( 'text_about', 'recent-posts', ), ), 'nav_menus' => array( 'primary' => array( 'name' => __( 'Primary Menu', 'stackwise' ), 'items' => array( 'link_home', 'link_about' => array( 'type' => 'custom', 'title' => _x( 'About', 'Theme starter content', 'stackwise' ), 'url' => home_url( '/#about' ), ), 'page_blog', 'link_contact' => array( 'type' => 'custom', 'title' => _x( 'Contact', 'Theme starter content', 'stackwise' ), 'url' => home_url( '/#contact' ), ), ), ), 'footer' => array( 'name' => __( 'Footer Menu', 'stackwise' ), 'items' => array( 'page_about' => array( 'type' => 'post_type', 'object' => 'page', 'object_id' => '{{about}}', ), 'page_blog', 'page_contact', ), ), ), ); } /** * Include additional files */ // Custom template tags. require STACKWISE_DIR . '/inc/template-tags.php'; // Template functions. require STACKWISE_DIR . '/inc/template-functions.php'; // Customizer additions. require STACKWISE_DIR . '/inc/customizer.php'; // Block patterns. require STACKWISE_DIR . '/inc/block-patterns.php'; /** * Add custom body classes * * @param array $classes Classes for the body element. * @return array */ function stackwise_body_classes( $classes ) { // Add a class if there is a custom header. if ( has_header_image() ) { $classes[] = 'has-header-image'; } // Add class for front page. if ( is_front_page() && ! is_home() ) { $classes[] = 'is-front-page'; } // Add class for singular views. if ( is_singular() ) { $classes[] = 'is-singular'; } return $classes; } add_filter( 'body_class', 'stackwise_body_classes' ); /** * Add a pingback url auto-discovery header for single posts, pages, or attachments. */ function stackwise_pingback_header() { if ( is_singular() && pings_open() ) { printf( '', esc_url( get_bloginfo( 'pingback_url' ) ) ); } } add_action( 'wp_head', 'stackwise_pingback_header' ); /** * Add preconnect for Google Fonts. * * @param array $urls URLs to print for resource hints. * @param string $relation_type The relation type the URLs are printed. * @return array URLs to print for resource hints. */ function stackwise_resource_hints( $urls, $relation_type ) { if ( 'preconnect' === $relation_type ) { $urls[] = array( 'href' => 'https://fonts.googleapis.com', ); $urls[] = array( 'href' => 'https://fonts.gstatic.com', 'crossorigin', ); } return $urls; } add_filter( 'wp_resource_hints', 'stackwise_resource_hints', 10, 2 ); /** * Modify excerpt length * * @param int $length Excerpt length. * @return int Modified excerpt length. */ function stackwise_excerpt_length( $length ) { if ( is_admin() ) { return $length; } return 20; } add_filter( 'excerpt_length', 'stackwise_excerpt_length' ); /** * Modify excerpt more string * * @param string $more More string. * @return string Modified more string. */ function stackwise_excerpt_more( $more ) { if ( is_admin() ) { return $more; } return '…'; } add_filter( 'excerpt_more', 'stackwise_excerpt_more' );