• Resolved alyssian

    (@alyssian)


    hi there,

    i have created a child theme and it the parent theme has a fancy box feature, which i would like to make a small edit to.

    in the parent theme functions.php file the the code is as follow for the the scripts:

    // Load Required Theme Scripts
    function sf_theme_js() {
    if (is_admin()) return;
    wp_enqueue_script(‘jquery’);
    wp_enqueue_script(‘fade’, THEME . ‘/scripts/jquery.fade.js’, ‘jquery’);
    wp_enqueue_script(‘superfish’, THEME . ‘/scripts/jquery.superfish.js’);
    wp_enqueue_script(‘easing’, THEME . ‘/scripts/jquery.easing.js’, ‘jquery’);
    wp_enqueue_script(‘coda’, THEME . ‘/scripts/jquery.coda.js’, ‘jquery’);
    wp_enqueue_style(‘fancybox’, THEME . ‘/scripts/fancybox/style.css’);
    wp_enqueue_script(‘fancybox’, THEME . ‘/scripts/fancybox/jquery.fancybox.js’, ‘jquery’);
    }
    add_action(‘init’, sf_theme_js);

    i’ve uploaded the scripts folder to my child theme, but i cannot figure out how to get the fancybox feature to work the way i want it to through the child theme. what code do i input in the child theme functions.php to load the fancy box script?

    thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Try something like:

    remove_action('init', 'sf_theme_js');
    add_action('init', 'my_sf_theme_js');
    function my_sf_theme_j() {
    [ your fancybox calls go here ]
    }

    in the child theme’s functions.php file.

    Thread Starter alyssian

    (@alyssian)

    hi thanks for your help!

    well, my apologies as i am not a programmer and i just sort of piece things together…

    here’s what i ended up placing in my functions.php file:

    <?php
    remove_action(‘init’, ‘sf_theme_js’);
    add_action(‘init’, ‘my_sf_theme_js’);
    function my_sf_theme_js() {
    wp_register_script(‘fancybox’, get_bloginfo(‘stylesheet_directory’) . ‘/scripts/fancybox/jquery.fancybox.js’, ‘jquery’);
    wp_enqueue_style(‘fancybox’, get_bloginfo(‘stylesheet_directory’) . ‘/scripts/fancybox/style.css’););
    }
    ?>

    and i got this error:
    Parse error: syntax error, unexpected ‘)’ in /home/kakaduna/public_html/wp-content/themes/kakadu-native/functions.php on line 6

    then i tried this too and it doesn’t work either:

    <?php
    remove_action(‘init’, ‘sf_theme_js’);
    add_action(‘init’, ‘my_sf_theme_js’);
    function my_sf_theme_js() {
    wp_register_script(‘fancybox’, get_bloginfo(‘stylesheet_directory’) . ‘/scripts/fancybox/jquery.fancybox.js’, ‘jquery’);
    wp_enqueue_script(‘fancybox’);
    }
    ?>

    i don’t get an error message (well i do on some pages, but not others), but it changes my background image and the fancy box doesn’t work at all.

    What’s on line 6?

    as for your error message, you have an extra );
    here:

    wp_enqueue_style('fancybox', get_bloginfo('stylesheet_directory') . '/scripts/fancybox/style.css'););

    Thread Starter alyssian

    (@alyssian)

    i’m not sure what you mean when you say what is on line 6?

    Line 6 of functions.php. Try:

    <?php
    remove_action('init', 'sf_theme_js');
    add_action('init', 'my_sf_theme_js');
    function my_sf_theme_js() {
    wp_register_script('fancybox', get_bloginfo('stylesheet_directory') . '/scripts/fancybox/jquery.fancybox.js', 'jquery');
    wp_enqueue_style('fancybox', get_bloginfo('stylesheet_directory') . '/scripts/fancybox/style.css');
    }
    ?>
    Thread Starter alyssian

    (@alyssian)

    thanks for your reply!

    i deleted the extra ); and the same thing is happening with that code as with the code below it. it changes my background to the default parent theme background and then i get this error on one of the pages:

    Warning: Cannot modify header information – headers already sent by (output started at /home/kakaduna/public_html/wp-content/themes/kakadu-native/functions.php:10) in /home/kakaduna/public_html/wp-includes/pluggable.php on line 890

    and the fancy box feature does not work at all when i click on t thumbnail photo.

    Thread Starter alyssian

    (@alyssian)

    i copied and pasted your code, which looks the same as removing the extra ); and i am having that same issue with the background and this error message:

    Warning: Cannot modify header information – headers already sent by (output started at /home/kakaduna/public_html/wp-content/themes/kakadu-native/functions.php:10) in /home/kakaduna/public_html/wp-includes/pluggable.php on line 890

    and the fancy box feature does not work at all when i click on the thumbnail photo.

    does it have something to do with the stylesheet that is being called in? why would it revert to the default parent theme background?

    Thread Starter alyssian

    (@alyssian)

    do you think this would also solve the problem with the background defaulting and the fancybox feature not working? because that error is only showing up on one page. but the other problems are on all pages.

    It will remove the header warning – which would be a start.

    Thread Starter alyssian

    (@alyssian)

    thank you so much for your help!!! i deleted one blank line from my functions.php code so it looks like this:

    <?php
    remove_action(‘init’, ‘sf_theme_js’);
    add_action(‘init’, ‘my_sf_theme_js’);
    function my_sf_theme_js() {
    wp_register_script(‘fancybox’, get_bloginfo(‘stylesheet_directory’) . ‘/scripts/fancybox/jquery.fancybox.js’, ‘jquery’);
    wp_enqueue_style(‘fancybox’, get_bloginfo(‘stylesheet_directory’) . ‘/scripts/fancybox/style.css’);
    }
    ?>
    <?php
    // Sidebar Widgets
    register_sidebar(array(‘name’=>’Contact Page’,
    ‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,
    ‘after_widget’ => ‘</div>’,
    ‘before_title’ => ‘<h3>’,
    ‘after_title’ => ‘</h3>’,
    ));
    ?>

    and now it’s all working!

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

The topic ‘child theme and editing scripts from parent theme’ is closed to new replies.