/* 
Theme Name: Hello Elementor Child
Theme URI: https://github.com/elementor/hello-theme-child/
Description: Hello Elementor Child is a child theme of Hello Elementor, created by Elementor team
Author: Elementor Team
Author URI: https://elementor.com/
Template: hello-elementor
Version: 2.0.0
Text Domain: hello-elementor-child
License: GNU General Public License v3 or later.
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Tags: flexible-header, custom-colors, custom-menu, custom-logo, editor-style, featured-images, rtl-language-support, threaded-comments, translation-ready
*/

/* Add your custom styles here */

add_filter('use_block_editor_for_post', '__return_false');

add_action('template_redirect', function() {
    global $wp_query;
    
    // اگر المنتور فعال است و کوئری آرشیو برای URL ناموجود بارگذاری شده
    if (class_exists('Elementor\Plugin') && $wp_query->is_archive && !have_posts()) {
        // بررسی اگر URL تک‌قسمتی است
        $requested_path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
        if (count(explode('/', $requested_path)) === 1) {
            // اگر با هیچ پست‌تایپ، دسته‌بندی یا taxonomy مطابقت ندارد
            if (!get_page_by_path($requested_path) && !is_category($requested_path) && !is_tag($requested_path) && !is_tax() && !is_post_type_archive($requested_path)) {
                $wp_query->set_404();
                status_header(404);
                nocache_headers();
                // بارگذاری قالب 404
                if (file_exists(get_404_template())) {
                    include(get_404_template());
                    exit;
                }
            }
        }
    }
});

