How to remove a php hook from a Wordpress theme - php

I'm trying to remove some hooks so that product categories don't show up on the homepage (of a Wordpress Storefront child theme).
I have the following code in my functions.php, which isn't working:
/**
* REMOVE SECTIONS ON HOMEPAGE
*/
add_action( 'init', 'remove_storefront_on_sale_products', 10 );
function remove_storefront_on_sale_products () {
?>
remove_action( 'homepage', 'storefront_on_sale_products', 60 );
<?php
}

Your code aint working because your line remove_action() is located outside of the php-tags.
Remove ?> and <?php in your above code and you should be fine.

First of all wordpress has not any action like "homepage" so you need to verify which action you are calling so if you want to remove function output only from homepage then you can do it by conditionally and secondly you didn't write proper php code, To achieve this you can write following in method.
if(!is_home()){
//Do stuff here if it is not homepage
}
OR
if(get_the_ID()!=101){ //101 your page id in which you don't want to show this
//Do stuff here if it is not homepage
}
I hope this may help you.

Related

How to add_action to Woocommerce hook?

I simply want to add an action to an existing Woocommerce hook (woocommerce_after_cart in this case). After adding a function with add_action() and loading the page back up, my function doesn't run. Not until I manually do_action() does my function finally run. I just want to know why when I add the action originally, it's not being acknowledged.
I've already checked out Wordpress codex for hooks and seems like I'm doing everything correct. I'm adding the action in a custom theme, not functions.php but I've tried that too.
Full thing looks like this:
function abc() {
print_r("hello world");
}
add_action('woocommerce_after_cart','abc');
Hello world does not print on page load, only after I call do_action(), why?
In order for any add_action() to work a do_action() must be called.
The woocommerce_after_cart action is called in the template "/cart/cart.php"
https://github.com/woocommerce/woocommerce/search?utf8=%E2%9C%93&q=woocommerce_after_cart
In your theme or child theme do you have the file "/woocommerce/cart/cart.php"?
It could be that the WooCommerce cart template is being overridden and that the template does not have the <?php do_action( 'woocommerce_after_cart' ); ?> call.
I have tested your abc function and it works in a vanilla out of the box install of Woo and WP.
You need to add the <?php do_action( 'woocommerce_after_cart' ); ?> action to the cart.php template file.
Hope this helps :)

Remove the breadcrumbs in wordpress using hook

To remove the breadcrumbs I have a solution using css which I have used but I want to remove that using hook instead of css.
.breadcrumbs {
display:none;
}
Please let me know the hook to remove the breadcrumbs from all pages.
Hook to remove breadcrumb is following. Add following code in your theme's functions.php file.
add_action( 'init', 'd_remove_breadcrumb');
function d_remove_breadcrumb() {
remove_action( 'storefront_content_top', 'woocommerce_breadcrumb', 10);
}
I found out that I could go into its header-page file and just remove/comment it out.
It already had a do_action there, and if I then used a remove_action in functions.php, it came out an error.
Thank you all for using some time to answer and try to help, which made me think in some other way than I usually do.

How to place content from function in My Account in Woocommerce?

Hi i have this function inserted into functions.php in my theme:
function woocommerce_after_account_navigation(){
$html = '<h3>Title</h3>';
$html.='<li>Text1</li>';
$html.='<li>Text2</li>';
echo $html;
}
and have placed this hook into navigation.php file from WooCommerce templates
<?php do_action( 'woocommerce_after_account_navigation' ); ?>
but seems that dont show nothing from content that i placed into functions.php
Can someone help me what is wrong with this hook ?
Youn don't need to change anything in the My account templates (as you are using an existing hook)… To get your custom content displayed, you should need to make it this way:
add_action( 'woocommerce_after_account_navigation', 'custom_content_after_account_navigation' );
function custom_content_after_account_navigation(){
$html = '<h3>Title</h3>';
$html.='<li>Text1</li>';
$html.='<li>Text2</li>';
echo $html;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested on WooCommerce 3 and works.
This custom content will be displayed below the My Account Menu

program custom wordpress plugin to output only to a specific page

I need to know how to take the output of a custom built Wordpress plugin and output it onto a specific page.
I know that I need to use the add_action() / add_filter() functions to call the function which outputs the plugins output when a wordpress hook function runs.
Currently I am using the 'the_content' hook.
This outputs my plugins output to all pages in my theme which call the the_content() function.
Which hook can I use to make the output only appear on a specific page.
Also
It would be useful to know how to create a page using my plugin.
Checkout is_page()
if (is_page(123)) {
// put your hooks here
}
put your code in a file inside plugin directory
then
use this
function page_directory()
{
if(is_page('123')){
$dir = plugin_dir_path( __FILE__ );
include($dir."custom/page.php");
die();
}
}
add_action( 'wp', 'page_directory' );

Wordpress - Plugin. using remove_action for favorite_actions

Learning php, figure as well as following tutorials doing some practical useful stuff is import. So a wordpress plugin....
Trying to remove the favorite actions box that you get in the wordpress admin header.
<?php
/*
Plugin Name: Hide Favorite Actions
Plugin URI: http://www.mysite.com
Description: Allows you to remove the Screen Options and Help tabs from view
Author: Tai Havard
Version: 1.0
Author URI:
*/
add_action('admin_menu','removeHelpAndScreenOptions');
function removeHelpAndScreenOptions()
{
remove_action('favorite_actions');
}
?>
Plugins activated, function runs, I'm just not sure how to get hold of the favorite_actions correctly and wether remove_action is the correct function for use with the favorite_actions hook.
Thanks
Here's how remove action works:
remove_action( 'hook_name', 'function_name' );
That says you want to remove the function function_name from the hook hook_name. I don't know what the hook and function are fore removing help and screen options, though. If I remember correctly, those tabs are hardcoded into the actual admin pages.
I used that code and got an error in a template.php (presumably expecting an array) The box disappears if you return with an empty element, something like this:
add_filter('favorite_actions', 'no_fav');
function no_fav($actions) {
$actions = array(
'' => array(__(''), '')
);
return $actions;
}
I just deleted the strings, somebody could probably write a more elegant empty array.
In your plugin just add
function rb_ax() {
return;
}
add_filter( 'favorite_actions', 'rb_ax' );
And you're done.
this works for me, wp 3.0.5
/**
* Remove "Favorite actions" from Admin
*/
add_filter('favorite_actions', 'no_fav');
function no_fav($actions) {
return array();
}
I put it in functions.php, but it would probably work fine as a plugin.
returning nothing (void?) works, but writes Warning: Invalid argument supplied for foreach()...

Categories