I have a theme that defines a new post type but I want to remove that function in the child theme:
PARENT THEME FUNCTION:
add_action('init', 'portfolio_register');
function portfolio_register()
{
//post type definition
}
CHILD THEME FUNCTION:
This is what I tried but it is not working.
function child_remove_parent_function() {
remove_action( 'init', 'portfolio_register' );
}
add_action( 'init', 'child_remove_parent_function', 15 );
Anyone has an idea of what am I doing wrong?
Thanks in advance.
try this code before add action in child theme function.php
<?php
remove_action( 'init', 'portfolio_register' );
?>
or
<?php
add_action( 'after_setup_theme','remove_portfolio', 100 );
function remove_portfolio() {
remove_action( 'init', 'portfolio_register');
}
?>
Related
Remove CSS and JavaScript with a PHP function like this:
function disable_files() {
wp_dequeue_style('blocks');
wp_dequeue_style('library');
wp_dequeue_script( 'jquery-js' );
add_action('wp_enqueue_scripts', 'disable_files', 100); }
When I use this function in function.php nothing happens. Is there something missing in the script?
deregister was missing
function disable_files() {
wp_dequeue_style('blocks');
wp_dequeue_style('library');
wp_dequeue_script('jquery-js');
wp_deregister_style('blocks');
wp_deregister_style('library');
wp_deregister_script('jquery-js');
}
add_action( 'wp_enqueue_scripts', 'disable_files', 9999 );
add_action( 'wp_head', 'disable_files', 9999 );
We use a plugin which add a filter to hide some order meta. Now we want to remove them via child theme instead of editing the plugin file. I tried every answer from here but the action is not removed: https://wordpress.stackexchange.com/questions/240929/how-to-remove-action-from-plugin and Removing action added by a plugin in Wordpress
This is the Plugin function:
public function __construct() {
add_filter( 'woocommerce_order_item_get_formatted_meta_data', [ $this, 'hide_extra_data' ] );
}
I tried with that already, but I'm not sure if this is the right way to do it.
add_action( 'woocommerce_order_item_get_formatted_meta_data', 'remove_my_action', 1 );
function remove_my_action(){
remove_action('woocommerce_order_item_get_formatted_meta_data', 'hide_extra_data', 10, 1);
}
remove_action( 'wp_fwoocommerce_order_item_get_formatted_meta_dataooter', 'hide_extra_data', 1 );
Try like this:
add_action( 'plugins_loaded', 'webearth_remove_plugin_filter' );
function webearth_remove_plugin_filter() {
remove_filter( 'woocommerce_order_item_get_formatted_meta_data',
array('ClassName', 'hide_extra_data'),
10 );
}
Change ClassName with the name of the class used by the plugin, the Class where the constructor is.
A function in the parent functions.php is requiring an include. I have editted this file its calling, but obviously its still in the parent directory.
require get_template_directory() . '/inc/widgets/team-member.php';
How can i ammend the file url in the child functions.php?
Add this code in parent theme functions.php
add_action( 'wp_loaded', 'parent_prefix_load_classes', 10 );
function parent_prefix_load_classes()
{
define('MEMBER_FILE_URL', get_template_directory(). '/inc/widgets/team-member.php');
}
Use this code in chile theme
// Priority 11 to run after the parent theme's loader.
add_action( 'wp_loaded', 'child_prefix_create_objects', 11 );
function child_prefix_create_objects()
{
echo MEMBER_FILE_URL;
}
I have a problem with a plugin and WooCommerce.
So I have a plugin with an options page, and a custom checkbox on it.
When this checkbox is activated, I want to hide/remove the default WooCommerce related product container.
I can remove this container if I just add this code:
add_action( 'init', 'add_action_function');
function add_action_function(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
But the problem is that I need to call this function from inside another "add_filter" function.
In the moment I have something like this:
add_filter( 'woocommerce_after_single_product_summary', 'add_filter_function' );
function add_filter_function () {
// Get the plugin option
$active = get_option( 'prfx_active', 'no');
// If option value is "yes", remove the related products container
if ($active = 'yes') {
// I think this add_action call is wrong
add_action( 'init', 'add_action_function');
function add_action_function(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
}//END if $active = yes
// Do some other stuff here
}//END add_filter_function
But when I change the option in the admin-settings, nothing changes. So I think the "init" hook is not right here.
I cant find the right hook to make this work. What hook must I use when I want it to fire when the plugin options get updated?
Thanks in advanced,
Mo
Thanks to Danijel and his answers.
I dont know why I didnt think of it this way.
Maybe this was to much "action" for me on that late evening ;)
I now placed the "add_action" outside of the "add_filter" function and just do the conditional-check there.
This is working:
add_action( 'init', 'hide_related');
function hide_related () {
if ( get_option( 'prfx_active', 'no' ) == 'yes' ) {
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
};
add_filter( 'woocommerce_after_single_product_summary', 'add_filter_function' );
function add_filter_function () {
...
Im quite certain that WP init action is fired before woocommerce_after_single_product_summary filter, and also if ( $active = 'yes' { ... expression will always be evaluated as true ( use == ). Try with this simple example:
add_action( 'init', function() {
if ( get_option( 'prfx_active', 'no' ) == 'yes' )
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
});
Try moving your add_action_funciton outside of add_filter_function
add_filter( 'woocommerce_after_single_product_summary', 'add_filter_function' );
function add_action_function(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
function add_filter_function () {
// Get the plugin option
$active = get_option( 'prfx_active', 'no');
// If option value is "yes", remove the related products container
if ($active = 'yes') {
// I think this add_action call is wrong
add_action( 'init', 'add_action_function');
}//END if $active = yes
// Do some other stuff here
}//END add_filter_function
I am trying to enqueue a jQuery script to my Wordpress site but for some reason it is not adding. Below is my code I've added to my child theme's functions.php file.
<?php
function itm_adding_scripts() {
wp_register_script('my_amazing_script', '/wp-content/themes/italic-child/js/jQuery.equalHeights.js/js/jQuery.equalHeights.js', array('jquery'),'1.1', true);
wp_enqueue_script('my_amazing_script');
}
add_action( '_enqueue_scripts', 'itm_adding_scripts' );
?>
You have a typo in the action missing wp prefix
Change
add_action( '_enqueue_scripts', 'itm_adding_scripts' );
To
add_action( 'wp_enqueue_scripts', 'itm_adding_scripts' );
Reference: wp_enqueue_scripts docs
You have a typo in your action. It should be wp_enqueue_scripts
add_action( 'wp_enqueue_scripts', 'itm_adding_scripts' );