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' => '',
'default-text-color' => 'e6edf3',
'width' => 1200,
'height' => 400,
'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__( 'Sidebar', 'stackwise' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'stackwise' ),
'before_widget' => '',
'before_title' => '
',
)
);
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' => '',
)
);
}
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(),
null
);
// 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
);
// 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' );
/**
* 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 );
}
/**
* 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', "Full Stack Developer\nFrontend Engineer\nBackend Developer\nUI/UX Enthusiast" );
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 ( $accent_color !== '#58a6ff' ) {
$css .= ':root { --sw-color-accent: ' . esc_attr( $accent_color ) . '; }';
}
return $css;
}
/**
* Get starter content
*
* @return array Starter content array
*/
function stackwise_get_starter_content() {
return array(
'posts' => array(
'home' => array(
'post_type' => 'page',
'post_title' => esc_html_x( 'Home', 'Theme starter content', 'stackwise' ),
'post_content' => '',
),
'about' => array(
'post_type' => 'page',
'post_title' => esc_html_x( 'About', 'Theme starter content', 'stackwise' ),
'post_content' => esc_html_x( 'This is the about page. Tell visitors about yourself and your background.', 'Theme starter content', 'stackwise' ),
),
'contact' => array(
'post_type' => 'page',
'post_title' => esc_html_x( 'Contact', 'Theme starter content', 'stackwise' ),
'post_content' => esc_html_x( 'Get in touch! Add your contact form shortcode here.', 'Theme starter content', 'stackwise' ),
),
'blog' => array(
'post_type' => 'page',
'post_title' => esc_html_x( 'Blog', 'Theme starter content', 'stackwise' ),
'post_content' => '',
),
'project-one' => array(
'post_type' => 'post',
'post_title' => esc_html_x( 'E-Commerce Platform', 'Theme starter content', 'stackwise' ),
'post_content' => esc_html_x( 'A full-featured e-commerce platform built with React and Node.js.', 'Theme starter content', 'stackwise' ),
),
'project-two' => array(
'post_type' => 'post',
'post_title' => esc_html_x( 'Task Management App', 'Theme starter content', 'stackwise' ),
'post_content' => esc_html_x( 'A collaborative task management application with real-time updates.', 'Theme starter content', 'stackwise' ),
),
),
'nav_menus' => array(
'primary' => array(
'name' => esc_html__( 'Primary Menu', 'stackwise' ),
'items' => array(
'page_home' => array(
'type' => 'post_type',
'object' => 'page',
'object_id' => '{{home}}',
'title' => esc_html_x( 'Home', 'Theme starter content', 'stackwise' ),
),
'page_about' => array(
'type' => 'post_type',
'object' => 'page',
'object_id' => '{{about}}',
'title' => esc_html_x( 'About', 'Theme starter content', 'stackwise' ),
),
'page_blog' => array(
'type' => 'post_type',
'object' => 'page',
'object_id' => '{{blog}}',
'title' => esc_html_x( 'Blog', 'Theme starter content', 'stackwise' ),
),
'page_contact' => array(
'type' => 'post_type',
'object' => 'page',
'object_id' => '{{contact}}',
'title' => esc_html_x( 'Contact', 'Theme starter content', 'stackwise' ),
),
),
),
),
'options' => array(
'show_on_front' => 'page',
'page_on_front' => '{{home}}',
'page_for_posts' => '{{blog}}',
),
);
}
/**
* 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';
}
// Add class based on sidebar
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'no-sidebar';
}
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' );
/**
* Get project category for posts
*
* @return WP_Term|false Project category term or false.
*/
function stackwise_get_project_category() {
$category_slug = get_theme_mod( 'stackwise_project_category', 'portfolio' );
$category = get_term_by( 'slug', $category_slug, 'category' );
return $category;
}
/**
* Check if post is a project
*
* @param int|WP_Post $post Post ID or post object.
* @return bool True if post is a project.
*/
function stackwise_is_project( $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$project_category = stackwise_get_project_category();
if ( ! $project_category ) {
return false;
}
return has_category( $project_category->term_id, $post );
}
/**
* Enqueue block editor assets
*/
function stackwise_block_editor_assets() {
wp_enqueue_style(
'stackwise-editor-style',
STACKWISE_URI . '/assets/css/editor-style.css',
array(),
STACKWISE_VERSION
);
}
add_action( 'enqueue_block_editor_assets', 'stackwise_block_editor_assets' );