Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I understand you can add extra CSS on top of the parent theme, but how do you remove PHP code from functions.php?

I want to remove the Masonry plugin in twentyfourteen theme, and have located the piece of code on line 254.

    if ( is_active_sidebar( 'sidebar-3' ) ) {
    wp_enqueue_script( 'jquery-masonry' );
    }

If I'm editing the parent theme, I can just comment this block out /* */.

But I'm not aware of a way to change this is my child theme.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You can't actually "remove" PHP code from the parent theme. What you can do is undo things done there.

The counterpart of wp_enqueue_script is wp_dequeue_script.

If you put this in your functions.php it should remove the Masonry Plugin (untested)

add_action( 'wp_print_scripts', 'de_script', 100 );

function de_script() {
    wp_dequeue_script( 'jquery-masonry' );
}

Source: Function Reference/wp dequeue script @ Codex

As I haven't tested this be aware of the fact that this could have unwanted side effects if the theme relies on the Masonry Plugin.

share|improve this answer
    
Brilliant, thanks to both of you. The Masonry plugin was adding inline styling to my footer widgets which stopped them from working between 800 and 900px, so I'm quite happy with ripping it out. But I'll keep my eye on any other issues! –  pappy Mar 19 at 16:25

I think, if your problem its just that script, you just can deregister it your child theme:

function deregister_jqmasonry() {
   if ( is_active_sidebar( 'sidebar-3' ) ) {
       wp_deregister_script( 'jquery-masonry' );
   }
}
add_action( 'wp_enqueue_scripts', 'deregister_jqmasonry', 100 );

High priority of add_action ensures it runs at the end.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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