0

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');

2 Answers 2

0

In child theme's functions.php

<?php
remove_filter('comment_form_field_comment',99,1); ?>
0

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

Your Answer

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

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