CSS/Child Theme

I'm using a child theme for CSS changes. I have a couple plugins that need things commented out from their functions.php. If I do that directly, the changes get reversed every update.
How can I remove certain lines of code from a plugin's functions.php using child theme's functions.php?

  • Vaughan
    • Support/SLS MockingJay

    hi @PressLock

    you would need to create that same function in your childs functions.php

    but you can't name it the same.

    example

    parent functions.php

    function parent_function() {}

    child functions.php

    function parent_child_function() {}

    then you would need to copy the template files from your parent theme that use that function.

    so say

    single-page.php has a call to parent_function()

    you would copy single-page.php to your child theme

    then edit the file & search & replace all references to parent_function() with parent_child_function()

    hope this helps, if you require any further assistance, please let us know.

    thanks.

  • Imperative Ideas
    • HummingBird

    You're basically doing a fancy version of the same thing we use to replace the in-theme version of jQuery with the Google CDN version.

    function modify_jquery() {
    	if (!is_admin()) {
    		// comment out the next two lines to load the local copy of jQuery
    		wp_deregister_script('jquery');
    		wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', false, '1.9.1');
    		wp_enqueue_script('jquery');
    	}
    }
    add_action('init', 'modify_jquery');

    Same concept, just slightly more involved.

  • Imperative Ideas
    • HummingBird

    No problem Vaughan. I absolutely did not mean to jump on you for offering up advice. What you suggested was a perfectly rational way of handling things and it's exactly what I would have done before I read Justin Tadlock's book on WordPress development last year.

    I strongly recommend picking that up. Even if you aren't coding your own plugins, the understanding that will give you of the WordPress core is incredibly valuable.

  • PressLock
    • Design Lord, Child of Thor

    Ok, ready to ask another question :slight_smile:

    Struggling with this problem:
    My theme has a jquery call on top of the wordpress core call which is messing up a couple plugins.
    How do I get rid of it using child-theme? Little beyond me as it's tucked away in other stuff:

    if (!is_admin())
    add_action('wp_enqueue_scripts', 'responsive_js');

    if (!function_exists('responsive_js')) {

    function responsive_js() {
    // JS at the bottom for fast page loading.
    // except for Modernizr which enables HTML5 elements & feature detects.
    wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/responsive-modernizr.js', array('jquery'), '2.6.1', false);
    wp_enqueue_script('responsive-scripts', get_template_directory_uri() . '/js/responsive-scripts.js', array('jquery'), '1.2.2', true);
    wp_enqueue_script('responsive-plugins', get_template_directory_uri() . '/js/responsive-plugins.js', array('jquery'), '1.2.2', true);
    }

    }

    Thanks!

  • Imperative Ideas
    • HummingBird

    To do exactly what you ask?

    <?php wp_deregister_script('jquery'); ?>

    Here's the problem... see this?

    wp_enqueue_script('responsive-plugins', get_template_directory_uri() . '/js/responsive-plugins.js', array('jquery'), '1.2.2', true);

    That array says it's dependent on jQuery. The other scripts won't load in unless it's there.

    I'm going to go out on a limb and say you have a couple of plugins installed and one of them includes its own version of jQuery inside of the code. Two versions of jQuery on one site cause major headaches.

    Before sending you on a wild chase after the plugin, however, try this:

    http://wordpress.org/extend/plugins/use-google-libraries/

    That solves the problem about 85% of the time and makes it worse the other 15%.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.