__('Primary Menu', 'aj-square'),
));
// Register widget area (sidebar)
register_sidebar(array(
'name' => __('Main Sidebar', 'aj-square'),
'id' => 'main-sidebar',
'description' => __('Widgets added here will appear in the main sidebar.', 'aj-square'),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '',
));
}
add_action('after_setup_theme', 'aj_square_setup');
*/
function aj_square_setup() {
add_theme_support('automatic-feed-links');
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_theme_support('custom-logo');
add_theme_support('custom-header'); // for header image support
add_theme_support('custom-background'); // for background settings
add_theme_support('align-wide'); // Gutenberg wide/full-width support
add_theme_support('wp-block-styles'); // Block editor styles
add_theme_support('responsive-embeds'); // Make embeds responsive
add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption'));
add_theme_support('editor-styles'); // Editor styling
add_editor_style('assets/css/style.css'); // Link your editor stylesheet here
register_nav_menus(array(
'primary' => __('Primary Menu', 'aj-square'),
));
register_sidebar(array(
'name' => __('Main Sidebar', 'aj-square'),
'id' => 'main-sidebar',
'description' => __('Widgets added here will appear in the main sidebar.', 'aj-square'),
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
));
}
add_action( 'init', 'aj_square_register_block_styles' );
function aj_square_register_block_styles() {
// Example: Add custom styles to core/quote
register_block_style( 'core/quote', array(
'name' => 'fancy-quote',
'label' => __( 'Fancy Quote', 'aj-square' ),
'inline_style' => '.is-style-fancy-quote { font-style: italic; border-left: 4px solid #333; padding-left: 10px; }',
) );
}
add_action('after_setup_theme', 'aj_square_setup');
// Enqueue scripts and styles
function aj_square_scripts() {
// Theme main stylesheet
wp_enqueue_style('aj-square-root-style', get_stylesheet_uri(), array(), '1.0.0');
// Theme custom style
wp_enqueue_style('aj-square-style', get_template_directory_uri() . '/assets/css/style.css', array(), '1.0.0');
// Bootstrap (local)
wp_enqueue_style('bootstrap-css', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), '4.6.2');
// Font Awesome (local)
wp_enqueue_style('font-awesome', get_template_directory_uri() . '/assets/css/fontawesome.min.css', array(), '6.4.2');
// Bootstrap Icons (local)
wp_enqueue_style('bootstrap-icons', get_template_directory_uri() . '/assets/bootstrap-icons/bootstrap-icons.css', array(), '1.10.5');
// jQuery (use default from WordPress)
// Do not deregister!
// Bootstrap JS (local)
wp_enqueue_script('bootstrap-js', get_template_directory_uri() . '/assets/js/bootstrap.bundle.min.js', array('jquery'), '4.6.2', true);
// Custom JS (local)
wp_enqueue_script('aj-square-script', get_template_directory_uri() . '/assets/js/script.js', array('jquery'), '1.1.0', true);
}
add_action('wp_enqueue_scripts', 'aj_square_scripts');
// Enqueue admin styles
function aj_enqueue_admin_styles() {
wp_enqueue_style('aj-admin-style', get_template_directory_uri() . '/assets/css/admin-style.css', array(), '1.0.0');
// Enqueue comment reply if needed
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action('admin_enqueue_scripts', 'aj_enqueue_admin_styles');
// Elementor compatibility
function aj_square_elementor_support() {
add_theme_support('elementor');
}
add_action('after_setup_theme', 'aj_square_elementor_support');
// Content width
if (!isset($content_width)) {
$content_width = 1140;
}
// Excerpt function
function excerpt($num) {
global $post;
$limit = $num + 1;
$excerpt = explode(' ', get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(" ", $excerpt) . " Read More »";
echo $excerpt;
}
// Reading time
function get_reading_time($post_id) {
$content = get_post_field('post_content', $post_id);
$word_count = str_word_count(strip_tags($content));
return ceil($word_count / 200);
}
// Time ago format
function time_ago($post_id) {
$post_time = get_post_time('U', true, $post_id);
$time_difference = time() - $post_time;
if ($time_difference < 1) return 'Just now';
$time_units = array(
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach ($time_units as $unit => $unit_name) {
if ($time_difference >= $unit) {
$num = floor($time_difference / $unit);
return $num . ' ' . $unit_name . ($num > 1 ? 's' : '') . ' ago';
}
}
}
// Custom pagination
function pagination($pages = '', $range = 4){
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == ''){
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages) $pages = 1;
}
if(1 != $pages){
echo "\n";
}
}
// Header widget area
function register_header_widget_area() {
register_sidebar(array(
'name' => __('Header Widget Area', 'aj-square'),
'id' => 'header-widget-area',
'before_widget' => '',
'before_title' => '',
));
}
add_action('widgets_init', 'register_header_widget_area');
// Custom logo widget
function custom_logo_widget_init() {
register_sidebar(array(
'name' => __('Custom Logo Widget', 'aj-square'),
'id' => 'custom_logo_widget',
'before_widget' => '',
'after_widget' => '
',
));
}
add_action('widgets_init', 'custom_logo_widget_init');
/* Hero Section Widget Area */
function register_hero_section_widget_area() {
register_sidebar(array(
'name' => __('Hero Section Widget Area', 'aj-square'),
'id' => 'hero-section-widget-area',
'before_widget' => '',
'after_widget' => '
',
));
}
add_action('widgets_init', 'register_hero_section_widget_area');
// Custom Block widget area
function aj_square_register_custom_block() {
register_sidebar(array(
'name' => __('Custom Block', 'aj-square'),
'id' => 'custom-block',
'before_widget' => '',
'after_widget' => '
',
));
}
add_action('widgets_init', 'aj_square_register_custom_block');
// Register Footer UP custom Section type
function register_footerup_widget_area() {
register_sidebar(array(
'name' => __('FooterUp Widget Area', 'aj-square'),
'id' => 'footerup-widget-area',
'before_widget' => '',
));
}
add_action('widgets_init', 'register_footerup_widget_area');
//Footer Social media widget area
function aj_square_register_footer_social_media() {
register_sidebar(array(
'name' => __('Footer Social Media', 'aj-square'),
'id' => 'footer-social-media',
'before_widget' => '',
));
}
add_action('widgets_init', 'aj_square_register_footer_social_media');
/*---------------------------------------------------
Documentation Function
----------------------------------------------------*/
function aj_square_add_documentation_menu() {
add_menu_page(
__('AJ SQUARE', 'aj-square'), // Page title
__('AJ SQUARE', 'aj-square'), // Menu title
'manage_options', // Capability required to access the page
'aj-square-docs', // Menu slug
'aj_square_theme_docs', // Callback function to render the page content
'dashicons-book', // Icon for the menu
60 // Position (use a lower value for above Appearance or higher for below)
);
}
add_action('admin_menu', 'aj_square_add_documentation_menu');
// Render the Documentation Page Content
function aj_square_theme_docs() {
?>
- Themes".', 'aj-square'); ?>
Customize" and adjust the settings as per your preferences.', 'aj-square'); ?>