Child theme remove parent filter in functions

admin2025-01-07  7

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

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');
Share Improve this question asked Aug 14, 2019 at 10:27 user2821847user2821847 1
Add a comment  | 

2 Answers 2

Reset to default 0

In child theme's functions.php

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

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736254966a247.html

最新回复(0)