WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 '14 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


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.