Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Daniel Iser

    (@danieliser)

    @earnshaw24 – If you are referring to the following code then you likely need to leave off the <?php part on the first line.

    Also that code si meant for your themes funcitosn.php file not footer.php file. If you do the second it won’t even get called. Hope that helps.

    <?php
    add_action( 'wp_footer', 'my_custom_popup_scripts', 500 );
    function my_custom_popup_scripts() { ?>
    <script type="text/javascript">
    	(function ($, document, undefined) {
    		// Your custom code goes here.
    	}(jQuery, document))
    </script><?php
    }
    Thread Starter earnshaw24

    (@earnshaw24)

    Hi danieliser,

    Thanks for getting back to me,

    I’ve tried cutting the <?php off and adding it to the functions.php file but with no luck, it just crashes the site.

    If I paste the functions.php file below, can you try and tell me how it should look with the code correct?

    Many thanks,

    <?php
    
    /*-----------------------------------------------------------------------------------*/
    /*  Define variables
    /*-----------------------------------------------------------------------------------*/
    
    define('COMET_THEME_URI', get_template_directory_uri());
    define('COMET_THEME_DIR', get_template_directory());
    define('COMET_CSS_URI', COMET_THEME_URI . '/assets/css');
    define('COMET_JS_URI', COMET_THEME_URI . '/assets/js');
    define('COMET_FW_DIR', COMET_THEME_DIR . '/framework');
    
    /*-----------------------------------------------------------------------------------*/
    /*  Theme Setup
    /*-----------------------------------------------------------------------------------*/
    
    add_action('after_setup_theme', 'comet_theme_setup');
    
    if ( ! function_exists('comet_theme_setup') ) {
      function comet_theme_setup(){
    
        /* Load scripts and styles */
        add_action('wp_enqueue_scripts', 'comet_enqueue_assets');
    
        /* Load admin scripts and styles */
        add_action('admin_enqueue_scripts', 'comet_admin_assets');
    
        /* Load Text Domain*/
        load_theme_textdomain('comet-wp', get_template_directory() . '/languages');
    
        // add_editor_style( LIB_DIR . '/admin/css/admin-style.css' );
    
        /* Set the content width */
        if (!isset($content_width)){ $content_width = 1170; }
    
        /* Register menu */
        add_action('init', 'comet_menu_init');
    
        /* Add thumbnails support */
        add_theme_support( 'post-thumbnails' );
    
        /* Add WooCommerce Support */
        add_theme_support( 'woocommerce' );
    
        /* Add images sizes*/
        add_image_size('comet_medium', 960);
        add_image_size('comet_small', 550);
    
        // Post formats
        add_theme_support('post-formats', array('audio', 'video', 'quote', 'image', 'gallery', 'link'));
    
        add_theme_support( 'custom-background', array('default-color' => 'ffffff') );
        add_theme_support( 'automatic-feed-links' );
    
        if ( function_exists( '_wp_render_title_tag' ) ) {
          add_theme_support( 'title-tag' );
        }
      }
    }
    
    /* Register Fonts */
    
    function comet_fonts_url() {
      $font_url = '';
    
      $primary_font = comet_options('primary_font');
      $heading_font = comet_options('heading_font');
      $serif_font   = comet_options('serif_font');
      $cursive_font = comet_options('cursive_font');
    
      /* Translators: If there are characters in your language that are not
      * supported by Raleway, translate this to 'off'. Do not translate
      * into your own language.
      */
      $raleway = _x( 'on', 'Raleway font: on or off', 'comet-wp' );
    
      /* Translators: If there are characters in your language that are not
      * supported by Montserrat, translate this to 'off'. Do not translate
      * into your own language.
      */
      $montserrat = _x( 'on', 'Montserrat font: on or off', 'comet-wp' );
    
      /* Translators: If there are characters in your language that are not
      * supported by Halant, translate this to 'off'. Do not translate
      * into your own language.
      */
      $halant = _x( 'on', 'Halant font: on or off', 'comet-wp' );
    
      /* Translators: If there are characters in your language that are not
      * supported by Tangerine, translate this to 'off'. Do not translate
      * into your own language.
      */
      $tangerine = _x( 'on', 'Tangerine font: on or off', 'comet-wp' );
    
      if ( 'off' !== $raleway || 'off' !== $montserrat || 'off' !== $halant || 'off' !== $tangerine ) {
        $font_families = array();
      }
    
      if ('off' !== $raleway && empty($primary_font['font-family']) || $primary_font['font-family'] == 'Raleway') {
        $font_families[] = 'Raleway:300,400,500';
      }
      if ('off' !== $montserrat && empty($heading_font['font-family']) || $heading_font['font-family'] == 'Montserrat') {
        $font_families[] = 'Montserrat:400,700';
      }
      if ('off' !== $halant && empty($serif_font['font-family']) || $serif_font['font-family'] == 'Halant') {
        $font_families[] = 'Halant:300,400';
      }
      if ('off' !== $tangerine && empty($cursive_font['font-family']) || $cursive_font['font-family'] == 'Tangerine') {
        $font_families[] = 'Tangerine:400';
      }
    
      $font_url = add_query_arg( 'family', urlencode( implode($font_families, '|') ), "//fonts.googleapis.com/css" );
    
      return esc_url_raw($font_url);
    
    }
    
    /*-----------------------------------------------------------------------------------*/
    /* Enqueue scripts and styles */
    /*-----------------------------------------------------------------------------------*/
    if ( ! function_exists('comet_enqueue_assets') ) {
      function comet_enqueue_assets(){
    
        // Styles
        wp_register_style('bundle-css', COMET_CSS_URI . '/bundle.css');
        wp_enqueue_style('bundle-css');
    
        wp_enqueue_style('style', get_stylesheet_uri(), '');
    
        if (!class_exists('wp_less')) {
          wp_enqueue_style('theme', COMET_CSS_URI . '/theme.css', '');
        }
    
        wp_enqueue_style( 'comet-fonts', comet_fonts_url(), array(), '1.0.0' );
    
        // Scripts
        wp_enqueue_script('google-maps', 'https://maps.google.com/maps/api/js', '', false, true);
        wp_enqueue_script( 'bundle', COMET_JS_URI . '/bundle.js', array('jquery'), false, true );
    
        wp_enqueue_script('main', COMET_JS_URI . '/main.js', array('jquery'), false, true);
    
        if (comet_options('smooth_scroll')) {
          wp_enqueue_script('smooth-scroll', COMET_JS_URI . '/SmoothScroll.js', array('jquery'), false, true);
        }
    
        $script_variables = array(
          'ajax_url' => admin_url( 'admin-ajax.php' ),
          'template_dir' => get_stylesheet_directory_uri()
        );
    
        wp_localize_script('main', 'comet_var', $script_variables );
    
        if (is_single()) {
          wp_enqueue_script('comment-reply');
        }
    
      }
    }
    
    function add_require_scripts_files() {
     wp_enqueue_style('style', get_stylesheet_directory_uri().'/style.css', array(), '1.5.6.0', "all");
    }
    add_action( 'wp_enqueue_scripts', 'add_require_scripts_files' );
    
    /*-----------------------------------------------------------------------------------*/
    /* Enqueue admin scripts and styles */
    /*-----------------------------------------------------------------------------------*/
    if ( ! function_exists('comet_admin_assets') ) {
      function comet_admin_assets(){
    
        wp_enqueue_media();
    
        wp_enqueue_style('comet_themify', COMET_CSS_URI . '/lib/themify-icons.css');
        wp_enqueue_style('comet_etline', COMET_CSS_URI . '/lib/et-line-icons.css');
    
        wp_enqueue_style('comet_admin_style', COMET_THEME_URI.'/framework/admin/css/admin.css');
    
        wp_enqueue_script('comet_bs_js', COMET_JS_URI.'/lib/bootstrap.js');
        wp_enqueue_script('comet_admin_script', COMET_THEME_URI.'/framework/admin/js/admin.js');
    
      }
    }
    
    /*-----------------------------------------------------------------------------------*/
    /* Register nav menus */
    /*-----------------------------------------------------------------------------------*/
    if (! function_exists('comet_menu_init') ) {
      function comet_menu_init(){
        register_nav_menus(
          array(
            'primary'   =>  esc_html__('Header Navigation', 'comet-wp'),
          )
        );
      }
    }
    
    /*-----------------------------------------------------------------------------------*/
    /*  Call the framework
    /*-----------------------------------------------------------------------------------*/
    
    require_once COMET_FW_DIR . '/framework.php';
    Thread Starter earnshaw24

    (@earnshaw24)

    @danieliser

    Hi Daniel, sorry to bother you again, are you able to help with this? It’s been the bane of my life for the past week.

    Many thanks,

    Gareth

    Plugin Author Daniel Iser

    (@danieliser)

    @earnshaw24 – Adding just the following after the last line should work fine:

    add_action( 'wp_footer', 'my_custom_popup_scripts', 500 );
    function my_custom_popup_scripts() { ?>
    <script type="text/javascript">
    	(function ($, document, undefined) {
    		// Your custom code goes here.
    	}(jQuery, document))
    </script><?php
    }

    Definitely shouldn’t throw an error though like that.

    Plugin Author Daniel Iser

    (@danieliser)

    Closing this ticket due to inactivity. If your still having an issue post here and we will continue troubleshooting.

    Please take a moment to rate and review the plugin and or support.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Adding Javascript using Wp-Footer’ is closed to new replies.