0

I've created a child theme, and moved all the modifications I had in the parent theme functions.php into the child theme's functions.php. Now if I preview the theme, it is blank.

I've got three things - changing the number of tags displayed in the cloud, hiding a product category and displaying a Google books preview.

I can't see any errors in this code, and it works when it's in the parent.

I would appreciate any help, I'm totally stuck!

<?php

function change_tag_cloud_widget() {
    $args['number'] = 15;
    return $args;
}
add_filter( 'widget_tag_cloud_args', 'change_tag_cloud_widget' );

add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

function custom_pre_get_posts_query( $q ) {

if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() ) {

$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'hands-on' ), // Don't display products in the hands-on category on the shop page
'operator' => 'NOT IN'
)));
}

remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

    }

add_shortcode('gbooks', 'sc_embed_google_books');
function sc_embed_google_books( $atts ){
    extract(shortcode_atts(array(
            "id" => '',
            "width"  => '600',
            "height" => '900',
    ), $atts));
    return '<script type="text/javascript" src="http://books.google.com/books/previewlib.js"></script>
    <script type="text/javascript">
    GBS_insertPreviewButtonPopup("'.$id.'", '.$width.','.$height.');
    </script>';
}


function get_google_tag( $isbn_metadata ) {
return (
    /* '<span class="post-meta-key">Preview: </span>' . */
    '<script type="text/javascript" src="http://books.google.com/books/previewlib.js"></script>' .
    '<script type="text/javascript">' .
    'GBS_insertPreviewButtonPopup(\'ISBN:' . $isbn_metadata . '\');' .
    '</script>'
);
}

?>
6
  • Most probably you are getting a cannot redeclare fatal error? Commented Sep 4, 2014 at 7:24
  • Another thing, just to mention, do not use extract. Check in the codex in the shortcode API how to correctly construct a shortcode Commented Sep 4, 2014 at 7:28
  • Thanks for the input Pieter. I'm not sure how to tell if I'm getting a "cannot redeclare fatal error". I don't know what this means or how to fix it! I will ask the person who did the google shortcode to fix the extract thing.
    – RexTheRunt
    Commented Sep 4, 2014 at 10:22
  • Quick check, you said you copied these functions from the parent theme. Are these functions wrapped in a if(!function_exists()) condition. If not, you cannot just copy a function to the child theme. This will trigger a cannot redeclare fatal error. No 2 functions can have the same name, except under the condition as stated. Turn on debug in wp-config.php Commented Sep 4, 2014 at 11:01
  • No, I moved them - they are no longer in the parent - they were not included in the parent in the first place, I had added them.
    – RexTheRunt
    Commented Sep 4, 2014 at 11:56

1 Answer 1

0

I've created a child theme, and moved all the modifications I had in the parent theme functions.php into the child theme's functions.php

Don't move all the functions from the parent theme into the child theme, just add the modifications to the child theme and leave the parent functions.php as it came with the theme.

You are most likely loading the functions twice as a result.

Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)

http://codex.wordpress.org/Child_Themes#Using_functions.php

5
  • See my comment above - these are new functions not included with the parent.
    – RexTheRunt
    Commented Sep 4, 2014 at 11:59
  • When wp_debug is set to true in your wp_config.php file, what errors is it giving you? define( 'WP_DEBUG', true );
    – stemie
    Commented Sep 4, 2014 at 14:19
  • Fatal error: Cannot redeclare custom_pre_get_posts_query() in my_parent_theme/functions.php on line 42
    – RexTheRunt
    Commented Sep 4, 2014 at 14:28
  • Search for custom_pre_get_posts_query in your parent functions file and remove it, only have that function in your child theme. If there are two different functions with the same name, make them unique.
    – stemie
    Commented Sep 4, 2014 at 14:32
  • oh I just see what happened - in my child theme's style.css I had the @import set to the correct parent, but not the template. Thanks for putting me on the right track with the debug, Pieter & stemie.
    – RexTheRunt
    Commented Sep 4, 2014 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.