WordPress.org

Ready to get started?Download WordPress

Forums

child theme (3 posts)

  1. rich123123
    Member
    Posted 1 year ago #

    I am trying to run jquery script in a child theme on a different subdirectory.

    example
    child function has following snipit
    //************ begining
    if ( !is_admin() );
    function my_init_credit() {
    wp_enqueue_script( 'custom_script',get_bloginfo('get_stylesheet_directory_uri').'/js/hide_pay.js',
    array('jquery'));
    //wp_enqueue_script( 'custom_script', 'wp-content/themes/freelancer-child-1/js/hide_pay.js',
    //array('jquery'));
    }
    //This action ensures the my_init() function is called when a page loads.
    add_action('init', 'my_init_credit');
    //*********************end
    Hook in php page <?php wp_enqueue_script("jquery"); ?>

    the page is in a subdirectory of the parent called lib/myaccount/xxxx.php so I have added that page to the child theme under the same sub directory structure and am referencing the .js files testing both directly and with get_bloginfo above. The .js directory and file is also in the child theme file

    I have other hooks and jquery running fine but they are running in the header.php and are working fine

    I cannot seem to get the js file to load in the file that is in the subdirectory of my parent theme either by placing it in the child directly or setting it up in the child with the same directory structure as in the parent.

    I have checked firebug and the .js is not executing on that page.

    the jquery code hides an element when the file is loaded.

    I have run the jquery in firebug directly and it hides the element fine
    //**********js code below*********
    jQuery(document).ready(function(){
    var par = jQuery('.post_bid_btn');
    jQuery(par).hide();
    });

    Can anyone give me any in site into how to handle a php page other than the standard index or header or footer in the child theme to run a function from the child function.php

    Thanks
    rich

  2. paulwpxp
    Font hero
    Posted 1 year ago #

    I think you should take a closer look at 2nd parameter of wp_enqueue_script()
    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    See examples in the doc and compare to yours.

  3. rich123123
    Member
    Posted 1 year ago #

    Thanks paulwpxp
    For the 1000 foot view was the
    wp_enqueue_script( 'custom_script',get_bloginfo

    'custom_script' should have been hide_pay

    Now that it works has lead to another problem of coarse.

    I only need this to fire on one certain page I am using
    if (is_page(16));
    but it is initilising and being fired on other pages with the same class identifier
    any ideas up there in the 1000 foot view

    I am using
    add_action('init', 'my_init_credit');
    to initialize the hook

    any suggestions on another tag that could be used to initialize for a specific action like page load ?

    Thanks
    rich

Topic Closed

This topic has been closed to new replies.

About this Topic