open popup in theme editor file with code
-
I created my popup with Elementor Pro, and I created my page, and in the file manager I created my page1.php page in wp-content/hello-theme/page1.php and linked it directly to the page to which corresponds, my problem would be to open my popup created with Elementor for which I have its respective shortcode, but I also tried asking chatgpt, but to no avail, it never managed to solve my problem, all of this I would need to open with code, I hope someone can help me but only with the code, I’m not interested in installing any plugins for this
Page1.php code:
<?php /* * Template Name: Page 1 * Template Post Type: page */ get_header(); // Include the theme header ?> <style> /* CSS rules for layout */ @media (min-width: 1200px) { .page-header .entry-title, .site-footer .footer-inner, .site-footer:not(.dynamic-footer), .site-header .header-inner, .site-header:not(.dynamic-header), body:not([class*=elementor-page-]) .site-main { max-width: 100vw; } } @media (min-width: 992px) { .page-header .entry-title, .site-footer .footer-inner, .site-footer:not(.dynamic-footer), .site-header .header-inner, .site-header:not(.dynamic-header), body:not([class*=elementor-page-]) .site-main { max-width: 100vw; } } @media (min-width: 768px) { .page-header .entry-title, .site-footer .footer-inner, .site-footer:not(.dynamic-footer), .site-header .header-inner, .site-header:not(.dynamic-header), body:not([class*=elementor-page-]) .site-main { max-width: 100vw; } } @media (min-width: 576px) { .page-header .entry-title, .site-footer .footer-inner, .site-footer:not(.dynamic-footer), .site-header .header-inner, .site-header:not(.dynamic-header), body:not([class*=elementor-page-]) .site-main { max-width: 100vw; } } @media (max-width: 575px) { .page-header .entry-title, .site-footer .footer-inner, .site-footer:not(.dynamic-footer), .site-header .header-inner, .site-header:not(.dynamic-header), body:not([class*=elementor-page-]) .site-main { padding-inline-start: 0px; padding-inline-end: 0px; } } </style> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php // Check if the current page ID is the same as the Page 1 ID if (get_the_ID() == 2) { // Replace 2 with your actual page ID // Content specific to Page 1 ?> <div style="text-align: center; margin: 20px 0;"> <h1>Hello everyone</h1> </div> <?php // Assuming [elementor-template id="33"] is not necessary since we're invoking a popup, not embedding a template } else { // If not Page 1, show the generic page content while (have_posts()) { the_post(); the_content(); } } ?> </main><!-- #main --> </div><!-- #primary --> <?php get_footer(); // Include the theme footer ?> <script> document.addEventListener('DOMContentLoaded', function() { // Checking if the Elementor frontend and popup modules are available if (window.elementorFrontend && window.elementorFrontend.modules && window.elementorFrontend.modules.popup) { var PopupModule = window.elementorFrontend.modules.popup; // Show the Elementor popup with the specific ID setTimeout(function() { PopupModule.showPopup({id: 33}); }, 1000); // Delay of 1 second to ensure all components are fully loaded } }); </script>
functions.php code:
<?php /** * Theme functions and definitions * * @package HelloElementor */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } define( 'HELLO_ELEMENTOR_VERSION', '3.0.1' ); if ( ! isset( $content_width ) ) { $content_width = 800; // Pixels. } if ( ! function_exists( 'hello_elementor_setup' ) ) { /** * Set up theme support. * * @return void */ function hello_elementor_setup() { if ( is_admin() ) { hello_maybe_update_theme_version_in_db(); } if ( apply_filters( 'hello_elementor_register_menus', true ) ) { register_nav_menus( [ 'menu-1' => esc_html__( 'Header', 'hello-elementor' ) ] ); register_nav_menus( [ 'menu-2' => esc_html__( 'Footer', 'hello-elementor' ) ] ); } if ( apply_filters( 'hello_elementor_post_type_support', true ) ) { add_post_type_support( 'page', 'excerpt' ); } if ( apply_filters( 'hello_elementor_add_theme_support', true ) ) { add_theme_support( 'post-thumbnails' ); add_theme_support( 'automatic-feed-links' ); add_theme_support( 'title-tag' ); add_theme_support( 'html5', [ 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'script', 'style', ] ); add_theme_support( 'custom-logo', [ 'height' => 100, 'width' => 350, 'flex-height' => true, 'flex-width' => true, ] ); /* * Editor Style. */ add_editor_style( 'classic-editor.css' ); /* * Gutenberg wide images. */ add_theme_support( 'align-wide' ); /* * WooCommerce. */ if ( apply_filters( 'hello_elementor_add_woocommerce_support', true ) ) { // WooCommerce in general. add_theme_support( 'woocommerce' ); // Enabling WooCommerce product gallery features (are off by default since WC 3.0.0). // zoom. add_theme_support( 'wc-product-gallery-zoom' ); // lightbox. add_theme_support( 'wc-product-gallery-lightbox' ); // swipe. add_theme_support( 'wc-product-gallery-slider' ); } } } } add_action( 'after_setup_theme', 'hello_elementor_setup' ); function hello_maybe_update_theme_version_in_db() { $theme_version_option_name = 'hello_theme_version'; // The theme version saved in the database. $hello_theme_db_version = get_option( $theme_version_option_name ); // If the 'hello_theme_version' option does not exist in the DB, or the version needs to be updated, do the update. if ( ! $hello_theme_db_version || version_compare( $hello_theme_db_version, HELLO_ELEMENTOR_VERSION, '<' ) ) { update_option( $theme_version_option_name, HELLO_ELEMENTOR_VERSION ); } } if ( ! function_exists( 'hello_elementor_display_header_footer' ) ) { /** * Check whether to display header footer. * * @return bool */ function hello_elementor_display_header_footer() { $hello_elementor_header_footer = true; return apply_filters( 'hello_elementor_header_footer', $hello_elementor_header_footer ); } } if ( ! function_exists( 'hello_elementor_scripts_styles' ) ) { /** * Theme Scripts & Styles. * * @return void */ function hello_elementor_scripts_styles() { $min_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; if ( apply_filters( 'hello_elementor_enqueue_style', true ) ) { wp_enqueue_style( 'hello-elementor', get_template_directory_uri() . '/style' . $min_suffix . '.css', [], HELLO_ELEMENTOR_VERSION ); } if ( apply_filters( 'hello_elementor_enqueue_theme_style', true ) ) { wp_enqueue_style( 'hello-elementor-theme-style', get_template_directory_uri() . '/theme' . $min_suffix . '.css', [], HELLO_ELEMENTOR_VERSION ); } if ( hello_elementor_display_header_footer() ) { wp_enqueue_style( 'hello-elementor-header-footer', get_template_directory_uri() . '/header-footer' . $min_suffix . '.css', [], HELLO_ELEMENTOR_VERSION ); } } } add_action( 'wp_enqueue_scripts', 'hello_elementor_scripts_styles' ); if ( ! function_exists( 'hello_elementor_register_elementor_locations' ) ) { /** * Register Elementor Locations. * * @param ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager $elementor_theme_manager theme manager. * * @return void */ function hello_elementor_register_elementor_locations( $elementor_theme_manager ) { if ( apply_filters( 'hello_elementor_register_elementor_locations', true ) ) { $elementor_theme_manager->register_all_core_location(); } } } add_action( 'elementor/theme/register_locations', 'hello_elementor_register_elementor_locations' ); if ( ! function_exists( 'hello_elementor_content_width' ) ) { /** * Set default content width. * * @return void */ function hello_elementor_content_width() { $GLOBALS['content_width'] = apply_filters( 'hello_elementor_content_width', 800 ); } } add_action( 'after_setup_theme', 'hello_elementor_content_width', 0 ); if ( ! function_exists( 'hello_elementor_add_description_meta_tag' ) ) { /** * Add description meta tag with excerpt text. * * @return void */ function hello_elementor_add_description_meta_tag() { if ( ! apply_filters( 'hello_elementor_description_meta_tag', true ) ) { return; } if ( ! is_singular() ) { return; } $post = get_queried_object(); if ( empty( $post->post_excerpt ) ) { return; } echo '<meta name="description" content="' . esc_attr( wp_strip_all_tags( $post->post_excerpt ) ) . '">' . "\n"; } } add_action( 'wp_head', 'hello_elementor_add_description_meta_tag' ); // Admin notice if ( is_admin() ) { require get_template_directory() . '/includes/admin-functions.php'; } // Settings page require get_template_directory() . '/includes/settings-functions.php'; // Header & footer styling option, inside Elementor require get_template_directory() . '/includes/elementor-functions.php'; if ( ! function_exists( 'hello_elementor_customizer' ) ) { // Customizer controls function hello_elementor_customizer() { if ( ! is_customize_preview() ) { return; } if ( ! hello_elementor_display_header_footer() ) { return; } require get_template_directory() . '/includes/customizer-functions.php'; } } add_action( 'init', 'hello_elementor_customizer' ); if ( ! function_exists( 'hello_elementor_check_hide_title' ) ) { /** * Check whether to display the page title. * * @param bool $val default value. * * @return bool */ function hello_elementor_check_hide_title( $val ) { if ( defined( 'ELEMENTOR_VERSION' ) ) { $current_doc = Elementor\Plugin::instance()->documents->get( get_the_ID() ); if ( $current_doc && 'yes' === $current_doc->get_settings( 'hide_title' ) ) { $val = false; } } return $val; } } add_filter( 'hello_elementor_page_title', 'hello_elementor_check_hide_title' ); /** * BC: * In v2.7.0 the theme removed the
hello_elementor_body_open()
fromheader.php
replacing it withwp_body_open()
. * The following code prevents fatal errors in child themes that still use this function. */ if ( ! function_exists( 'hello_elementor_body_open' ) ) { function hello_elementor_body_open() { wp_body_open(); } } //PERMESSI PER VISUALIZZARE/ NASCONDERE UN SPECIFICO ARTICOLO/PAGINA/PRODOTTO, ETC... // Aggiungi i meta box in tutti i tipi di post pubblici add_action('add_meta_boxes', 'custom_add_meta_boxes'); function custom_add_meta_boxes() { $post_types = get_post_types(array('public' => true), 'names'); foreach ($post_types as $post_type) { add_meta_box('custom_roles_meta_box', 'Assegna Ruoli', 'custom_roles_meta_box_callback', $post_type, 'side', 'high'); add_meta_box('custom_product_id_meta_box', 'ID Prodotto', 'custom_product_id_meta_box_callback', $post_type, 'side', 'high'); } } function custom_roles_meta_box_callback($post) { $selected_roles = get_post_meta($post->ID, 'assigned_roles', true); $selected_roles = maybe_unserialize($selected_roles) ?: array(); global $wp_roles; echo '<select name="assigned_roles[]" multiple="multiple" style="width: 100%; height: 100px;">'; foreach ($wp_roles->roles as $role_value => $role_name) { echo '<option value="' . esc_attr($role_value) . '"' . (in_array($role_value, $selected_roles) ? ' selected' : '') . '>' . esc_html($role_name['name']) . '</option>'; } echo '</select>'; } function custom_product_id_meta_box_callback($post) { // Recupera l'ID del prodotto selezionato $selected_product_id = get_post_meta($post->ID, 'product_id', true); // Prepara l'elenco dei prodotti WooCommerce $args = array( 'post_type' => 'product', 'posts_per_page' => -1, 'post_status' => 'publish', ); $products = new WP_Query($args); // Dropdown per la selezione del prodotto echo '<select name="product_id" style="width: 100%;">'; echo '<option value="">Seleziona un Prodotto</option>'; if ($products->have_posts()) { while ($products->have_posts()) { $products->the_post(); $id = get_the_ID(); $name = get_the_title(); echo '<option value="' . esc_attr($id) . '"' . selected($selected_product_id, $id, false) . '>' . esc_html($name) . '</option>'; } } wp_reset_postdata(); echo '</select>'; } // Salva i metadati dei meta box add_action('save_post', 'custom_save_postdata'); function custom_save_postdata($post_id) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; if (isset($_POST['assigned_roles'])) { update_post_meta($post_id, 'assigned_roles', maybe_serialize($_POST['assigned_roles'])); } if (isset($_POST['product_id'])) { update_post_meta($post_id, 'product_id', $_POST['product_id']); } } // Verifica l'accesso al contenuto del post basato sui ruoli assegnati e sull'acquisto del prodotto add_action('wp', 'display_post_content_based_on_role_and_purchase'); function display_post_content_based_on_role_and_purchase() { if (!is_singular()) return; $post_id = get_the_ID(); $user_id = get_current_user_id(); $assigned_roles = get_post_meta($post_id, 'assigned_roles', true); $product_id = get_post_meta($post_id, 'product_id', true); $assigned_roles = maybe_unserialize($assigned_roles) ?: array(); $user_has_role = array_intersect($assigned_roles, wp_get_current_user()->roles) ? true : false; $user_bought_product = function_exists('wc_customer_bought_product') && wc_customer_bought_product('', $user_id, $product_id); } add_action('template_redirect', 'custom_page_template'); function custom_page_template() { // Array associativo degli ID delle pagine e dei rispettivi nomi dei template $custom_page_templates = array( 2 => 'page1.php', // Aggiungi qui altri ID di pagina e relativi nomi di template ); // Ottieni l'ID della pagina corrente $current_page_id = get_queried_object_id(); // Verifica se l'ID della pagina corrente è presente nell'array dei template personalizzati if (array_key_exists($current_page_id, $custom_page_templates)) { // Se l'ID della pagina corrente è presente nell'array, include il template specifico include(get_template_directory() . '/pages/' . $custom_page_templates[$current_page_id]); exit; // Termina il processo di caricamento della pagina } } // Funzione per gestire la richiesta AJAX e restituire il contenuto dello shortcode add_action('wp_ajax_load_elementor_content', 'load_elementor_content_handler'); add_action('wp_ajax_nopriv_load_elementor_content', 'load_elementor_content_handler'); function load_elementor_content_handler() { // Verifica l'esistenza di un ID template valido if (isset($_REQUEST['template_id'])) { $template_id = intval($_REQUEST['template_id']); echo do_shortcode('[elementor-template id="' . $template_id . '"]'); } wp_die(); // termina correttamente la richiesta AJAX }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘open popup in theme editor file with code’ is closed to new replies.