250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
)
);
add_theme_support(
'custom-background',
apply_filters(
'bsd_custom_background_args',
array(
'default-color' => 'ffffff',
'default-image' => '',
)
)
);
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
'navigation-widgets',
)
);
register_nav_menus(
array(
'menu-1' => esc_html__( 'Primary', 'basic-starter-dev' ),
'footer' => esc_html__( 'Footer Menu', 'basic-starter-dev' ),
)
);
// Load editor styles
add_editor_style( 'editor-style.css' );
}
add_action( 'after_setup_theme', 'bsd_setup' );
function bsd_register_block_styles() {
register_block_style(
'core/image',
array(
'name' => 'fancy-border',
'label' => __( 'Fancy Border', 'basic-starter-dev' ),
'inline_style' => '.is-style-fancy-border { border: 5px double #000; padding: 10px; }',
)
);
register_block_pattern(
'basic-starter-dev/hero-text',
array(
'title' => __( 'Hero Text Section', 'basic-starter-dev' ),
'description' => _x( 'A centered hero section with text.', 'Block pattern description', 'basic-starter-dev' ),
'content' => "
" . esc_html__('Welcome to Our Website!', 'basic-starter-dev') . "
",
)
);
}
add_action( 'init', 'bsd_register_block_styles' );
/**
* Set the content width
*/
function bsd_content_width() {
$GLOBALS['content_width'] = apply_filters( 'bsd_content_width', 640 );
}
add_action( 'after_setup_theme', 'bsd_content_width', 0 );
/**
* Register widget area
*/
function bsd_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Sidebar', 'basic-starter-dev' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'basic-starter-dev' ),
'before_widget' => '',
'before_title' => '',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Footer Widget Area', 'basic-starter-dev' ),
'id' => 'footer-1',
'description' => esc_html__( 'Add widgets here.', 'basic-starter-dev' ),
'before_widget' => '',
'before_title' => '',
)
);
}
add_action( 'widgets_init', 'bsd_widgets_init' );
/**
* Enqueue scripts and styles
*/
function bsd_scripts() {
wp_enqueue_style( 'bsd-style', get_stylesheet_uri(), array(), BSD_VERSION );
wp_style_add_data( 'bsd-style', 'rtl', 'replace' );
wp_enqueue_script(
'bsd-navigation',
get_template_directory_uri() . '/js/navigation.js',
array(),
BSD_VERSION,
true
);
wp_enqueue_script(
'bsd-custom',
get_template_directory_uri() . '/js/custom.js',
array('jquery'), // if your JS depends on jQuery
BSD_VERSION,
true
);
// Customizer live preview
if ( is_customize_preview() ) {
wp_enqueue_script(
'bsd-customizer',
get_template_directory_uri() . '/js/customizer.js',
array( 'jquery', 'customize-preview' ),
BSD_VERSION,
true
);
}
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'bsd_scripts' );
/**
* Custom Navigation Walker for better accessibility
*/
class BSD_Walker_Nav_Menu extends Walker_Nav_Menu {
public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
// Ensure $args works as object or array
$before = is_array( $args ) ? ( $args['before'] ?? '' ) : ( $args->before ?? '' );
$after = is_array( $args ) ? ( $args['after'] ?? '' ) : ( $args->after ?? '' );
$link_before = is_array( $args ) ? ( $args['link_before'] ?? '' ) : ( $args->link_before ?? '' );
$link_after = is_array( $args ) ? ( $args['link_after'] ?? '' ) : ( $args->link_after ?? '' );
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
// Add has-children helper class
$has_children = in_array( 'menu-item-has-children', $classes, true );
if ( $has_children ) {
$classes[] = 'has-children';
}
$class_names = implode(
' ',
apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args )
);
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$item_id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args );
$item_id = $item_id ? ' id="' . esc_attr( $item_id ) . '"' : '';
$output .= $indent . '';
// Link attributes
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) . '"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_url( $item->url ) . '"' : '';
// ARIA for submenu parents
if ( $has_children ) {
$attributes .= ' aria-haspopup="true" aria-expanded="false"';
}
// Build output
$item_output = $before;
$item_output .= '';
$item_output .= $link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $link_after;
// Submenu icon (decorative)
if ( $has_children ) {
$item_output .= ' ';
}
$item_output .= '';
$item_output .= $after;
$output .= apply_filters(
'walker_nav_menu_start_el',
$item_output,
$item,
$depth,
$args
);
}
}
/**
* Include theme files
*/
require get_template_directory() . '/inc/custom-header.php';
require get_template_directory() . '/inc/template-tags.php';
require get_template_directory() . '/inc/template-functions.php';
require get_template_directory() . '/inc/customizer.php';
if ( defined( 'JETPACK__VERSION' ) ) {
require get_template_directory() . '/inc/jetpack.php';
}
/**
* Add Theme Settings Page
*/
function bsd_add_theme_settings_page() {
add_menu_page(
__('Theme Settings', 'basic-starter-dev'),
__('Theme Settings', 'basic-starter-dev'),
'manage_options',
'bsd-theme-settings',
'bsd_render_theme_settings_page',
'dashicons-admin-generic',
3
);
}
add_action('admin_menu', 'bsd_add_theme_settings_page');
/**
* Render Theme Settings Page
*/
function bsd_render_theme_settings_page() {
?>
'bsd_sanitize_logo_dimension',
)
);
register_setting(
'bsd_theme_options',
'bsd_logo_height',
array(
'sanitize_callback' => 'bsd_sanitize_logo_dimension',
)
);
register_setting(
'bsd_theme_options',
'bsd_sticky_header',
array(
'sanitize_callback' => 'bsd_sanitize_sticky_header',
'default' => 'no',
)
);
}
add_action('admin_init', 'bsd_register_theme_settings');
/**
* Sanitize numeric logo dimensions.
*
* @param mixed $value Input value.
*
* @return string Sanitized dimension or empty string.
*/
function bsd_sanitize_logo_dimension( $value ) {
$value = absint( $value );
return $value ? (string) $value : '';
}
/**
* Sanitize sticky header option.
*
* @param mixed $value Input value.
*
* @return string Sanitized value ('yes' or 'no').
*/
function bsd_sanitize_sticky_header( $value ) {
return in_array( $value, array( 'yes', 'no' ), true ) ? $value : 'no';
}