Child theme remove parent filter in functions

by user2821847   Last Updated August 14, 2019 11:08 AM

Have a parent/child theme setup. The parent theme has a filter I want to remove. How do I remove these filters in the child theme functions?

/** --------- */
/** COMMENTS */
/** --------- */

/** FORMAT COMMENT REPLY FIELD */
add_filter('comment_form_field_comment', function () {
\XPress::registry()->loadJS('themehouse/xpress/comment.js');
return '<div data-xf-init="xpress-comment-form">' . \XPress::getEditorInstance('comment_content', 'comment') . '</div>';
}, 8);

/** READ XF FROALA EDITOR CONTENT ON SAVE */
add_filter('preprocess_comment', function ($data) {
$data['comment_content'] = \XPress::getEditorContent('comment_content') ?: $data['comment_content'];

if (empty($data['comment_content']) || $data['comment_content'] === 'x') {
wp_die(\XPress::xlink()->phrase('xpress_empty_comment_error'), \XPress::xlink()->phrase('xpress_empty_comment'));
}

return $data;
}, 99, 1);

For example using code like this in our child theme functions:

function remove_language_attributes() {
remove_filter('language_attributes', 'add_opengraph_doctype');
}
add_filter('init', 'remove_language_attributes');


Answers 2


In child theme's functions.php

<?php
remove_filter('comment_form_field_comment',99,1); ?>
Wordpress Dev
Wordpress Dev
August 14, 2019 10:40 AM

These filters have been added using anonymous functions, so you can't just remove_filter('filter_name', 'function_name') because function_name doesn't actually exist.

You can override the anonymous function by using another anonymous function and giving it the same priority. For example:

remove_filter( 'comment_form_field_comment', function(){}, 8 );

More info can be found here: Remove Actions/Filters added via Anonymous Functions

Andy Mardell
Andy Mardell
August 14, 2019 10:42 AM

Related Questions


How to construct function for applying filter?

Updated March 01, 2017 12:08 PM




function replace_text for entire page

Updated September 22, 2018 15:08 PM