__('Primary Menu', 'awwwards-custom'), 'footer' => __('Footer Menu', 'awwwards-custom') )); } add_action('after_setup_theme', 'my_theme_setup'); function check_elementor_dependency() { if (!is_plugin_active('elementor/elementor.php')) { add_action('admin_notices', 'show_elementor_warning'); add_action('wp_footer', 'show_elementor_frontend_warning'); } } function show_elementor_warning() { echo '

Warning: This theme requires Elementor. Please install and activate Elementor.

'; } function show_elementor_frontend_warning() { echo '
Warning: This theme requires Elementor. Please install and activate it.
'; } // Plugin Active Check ke liye include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); add_action('admin_init', 'check_elementor_dependency'); // Enqueue styles and scripts function my_theme_scripts() { wp_enqueue_style( 'my-theme-style', get_stylesheet_uri() ); wp_enqueue_style( 'custom-css', get_template_directory_uri() . '/assets/css/style.css' ); wp_enqueue_script( 'custom-js', get_template_directory_uri() . '/assets/js/script.js', array( 'jquery' ), null, true ); } add_action( 'wp_enqueue_scripts', 'my_theme_scripts' ); // Elementor Support function my_elementor_support() { add_theme_support( 'elementor' ); } add_action( 'after_setup_theme', 'my_elementor_support' ); // ------------------------------------------------------------------- // Elementor Template Importer for Pages // ------------------------------------------------------------------- function import_elementor_template( $page_id, $template_file ) { if ( ! class_exists( '\Elementor\Plugin' ) ) { return; } $file_path = get_template_directory() . '/elementor-templates/' . $template_file; if ( ! file_exists( $file_path ) ) { error_log( "Template file missing: " . $file_path ); return; } $template_content = file_get_contents( $file_path ); $decoded_data = json_decode( $template_content, true ); // Validate JSON if ( json_last_error() !== JSON_ERROR_NONE ) { error_log( "JSON Error: " . json_last_error_msg() ); return; } // Use Elementor's official importer if needed. $result = \Elementor\Plugin::$instance->templates_manager->import_template( [ 'fileData' => file_get_contents( $template_content ), 'fileName' => $template_file ] ); if ( ! is_wp_error( $result ) ) { update_post_meta( $page_id, '_elementor_data', wp_slash( json_encode( $decoded_data['content'] ) ) ); update_post_meta( $page_id, '_elementor_edit_mode', 'builder' ); update_post_meta( $page_id, '_elementor_template_type', 'page' ); } } // Automatic Page Setup with Safety Checks function my_theme_auto_setup() { // Pages and their associated JSON files (for landing, archive, single post) $default_pages = [ 'Landing Page' => 'landing.json', 'Archive Page' => 'archive.json', 'Single Post' => 'single.json' ]; foreach ( $default_pages as $page_title => $template_file ) { // Create page if it doesn't exist if ( ! get_page_by_title( $page_title ) ) { $page_id = wp_insert_post( [ 'post_title' => $page_title, 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => '' ] ); // If page was created successfully, schedule template import on init if ( ! is_wp_error( $page_id ) ) { add_action( 'init', function() use ( $page_id, $template_file ) { import_elementor_template( $page_id, $template_file ); }, 20 ); } } } } add_action( 'after_switch_theme', 'my_theme_auto_setup' ); // Admin Notice for Template Import Errors function my_theme_admin_notice() { $landing_page = get_page_by_title( 'Landing Page' ); if ( $landing_page && ! get_post_meta( $landing_page->ID, '_elementor_data', true ) ) { echo '
'; echo '

Templates not applied! Please re-save permalinks or click here to apply templates manually.

'; echo '
'; } } add_action( 'admin_notices', 'my_theme_admin_notice' ); // Manual Template Application (via URL parameter) if ( isset( $_GET['force_apply_templates'] ) && current_user_can( 'manage_options' ) ) { add_action( 'init', function() { $pages = [ 'Landing Page' => 'landing.json', 'Archive Page' => 'archive.json', 'Single Post' => 'single.json' ]; foreach ( $pages as $title => $file ) { $page = get_page_by_title( $title ); if ( $page ) { import_elementor_template( $page->ID, $file ); } } wp_redirect( admin_url( '?templates_applied=1' ) ); exit; } ); } // Set the Landing Page as the Homepage function set_custom_homepage() { $landing_page = get_page_by_title( 'Landing Page' ); if ( $landing_page ) { update_option( 'page_on_front', $landing_page->ID ); update_option( 'show_on_front', 'page' ); } } add_action( 'init', 'set_custom_homepage' ); function create_blog_page_on_activation() { $blog_page = get_page_by_title('Blogs'); if (!$blog_page) { $blog_page_id = wp_insert_post([ 'post_title' => 'Blogs', 'post_content' => '', 'post_status' => 'publish', 'post_type' => 'page', ]); // if ($blog_page_id) { // update_option('page_for_posts', $blog_page_id); // } } } add_action('after_switch_theme', 'create_blog_page_on_activation'); function enqueue_custom_styles() { wp_enqueue_style('custom-style', get_stylesheet_uri()); } add_action('wp_enqueue_scripts', 'enqueue_custom_styles'); function custom_page_templates($templates) { $templates['page-blogs.php'] = 'Blogs'; return $templates; } add_filter('theme_page_templates', 'custom_page_templates'); function mytheme_register_footer_widgets() { register_sidebar(array( 'name' => __('Footer Widget Area', 'your-theme-textdomain'), 'id' => 'footer-widget', 'description' => __('Widgets added here will appear in the footer.', 'your-theme-textdomain'), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', )); } add_action('widgets_init', 'mytheme_register_footer_widgets'); ?>