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()...
Related
Sorry to repeat this question again, but this drives me crazy?
How can I remove the wordpress 5.6.1 meta tag from the header in my wordpress template?
<meta name="generator" content="WordPress 5.6.1" />
I tried all code snippets that I found on the internet and placed it in the functions.php page of my theme and child theme. So code snippets like below do not work in my case:
// remove version from head
remove_action('wp_head', 'wp_generator');
// remove version from rss
add_filter('the_generator', '__return_empty_string');
// remove version from scripts and styles
function collectiveray_remove_version_scripts_styles($src) {
if (strpos($src, 'ver=')) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
add_filter('style_loader_src', 'collectiveray_remove_version_scripts_styles', 9999);
add_filter('script_loader_src', 'collectiveray_remove_version_scripts_styles', 9999);
I also commented the code add_filter from the default-filters.php page, but this didn't help either:
add_action( 'wp_head', 'wp_generator' );
So my conclusion must be that info about the wordpress version must be added somewhere else or in a later stage?
Are there any tips where I could start looking after and what specific piece of code I should look for? Is the version number stored somewhere in the db? Is there specific code that is executed after functions.php that can overrule the initial removal by the code that seems to work perfectly elsewhere? I don't think the version number is hardcoded ad I did not find it with multiple keyword searches.
I am using wordpress 5.6.1 with a third-party theme. I made modifications, so I am using the child theme. I modified the prefix of my database tables (in case it would matter). My site is not yet online.
Based on the comment of Peter, I digged a bit further, but still no succes...
In my header.php of my theme, there is only mentionned to use the wp_head function:
<?php wp_head(); ?>
I have commented out the wp_head function in wp-includes\general-template.php:
function wp_head() {
/**
* Prints scripts or data in the head tag on the front end.
*
* #since 1.5.0
*/
do_action( 'wp_head' );
}
I have commented out the function wp_generator in wp-includes\general-template.php
function wp_generator() {
/**
* Filters the output of the XHTML generator tag.
*
* #since 2.5.0
*
* #param string $generator_type The XHTML generator.
*/
the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
}
I commnented out a few more instances related to wp_head. None of them have the desired result. In my theme there is no specific function appearing related to wp_head.
I have no clue how to solve this further?
I always use the following filter hook, plus remove_action hook. They work seamlessly fine!!!
function disable_wp_version(){
return '';
}
add_filter('the_generator', 'disable_wp_version');
remove_action('wp_head', 'wp_generator');
Because pages get cached, IT'S VERY IMPORTANT TO CHECK THEM IN AN INCOGNITO(CHROME) / PRIVATE(FIREFOX) WINDOW. OR TRY TO DELETE YOUR BROWSER CACHE, BEFORE YOU TEST THOSE HOOKS!!!
I just tested them out on "2021" wordpress core default theme as well as a custom theme, they still work fine! (Wordpress 5.6)
I'm working on a project that is running of a child theme of TwentySeventeen and whilst the rest of the site doesn't have a sidebar, WooCommerce seems to have it.
For example, the shop page has it - I have tried a few things already and none work without caveats or didn't work at all:
I tried copying archive-product.php to my theme dir in woocommerce/archive-product.php and removing the below:
do_action( 'woocommerce_after_main_content' );
This didn't work.
I then tried doing:
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',10);
...this didn't work either.
I found this answer and it worked, but didn't make the page full width (still had space for the sidebar) and a comment on the answer noted using that method isn't a great idea.
I also found this answer but it involves adding CSS, something I'd like to avoid as it isn't the most robust method in-case class names change in the future etc...
Isn't there a proper way of doing this without potential side affects?
Please, add this code to your functions.php
For remove only woocommerce side bar
function disable_woo_commerce_sidebar_mms() {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
}
add_action('init', 'disable_woo_commerce_sidebar_mms')
for remove all side bars
function remove_sidebar_mms() {
return false;
}
add_filter( 'is_active_sidebar', 'remove_sidebar_mms', 10, 2 );
OR
You can try this with to increase the priority hope fully its work
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',25);
With the help of Mannu saraswat's answer and some fiddling around I came up with a solution:
// Remove the sidebar
add_action('get_header', 'blm_wc_remove_sidebar_check', 10);
// Removes the sidebar
function blm_wc_remove_sidebar($index) {
return false;
}
// Check to see if we're on a WooCommerce page and if so, remove the sidebar
function blm_wc_remove_sidebar_check() {
if ( is_woocommerce() ) {
add_filter('is_active_sidebar', 'blm_wc_remove_sidebar', 10, 1);
}
}
This avoids having to do the is_active_sidebar check / filter addition on non-WooCommerce pages.
Maybe there is a cleaner way to do this, but this worked for me.
I have a function in my theme functions.php file which returns a value:
function my_theme_function() {
return "100";
}
Anywhere in my theme templates I can simply do this...
echo my_theme_function()
...and I see the number 100 on the page. That's cool.
But in my plugin I would have expected to be able do also get access to this function by echoing my_theme_function() but instead I get a 'call to undefined function' error.
The strangest part is I'm certain this was working a couple of days ago, but I've not touched the code since. I suspect some WordPress shenanigans, but I don't know why or how to get around this.
The reason you may take this result can be the order in which the theme and the plugins are loaded.
For example, your plugin can get loaded before the theme, and obviously, in this case, the function it is not available in your plugin source code.
The solution to this issue are the WordPress Hooks. I don't know what is your plugin code style, but you can bootstrap your plugin in the init hook or even better in the after_setup_theme.
So for example, let's say, you need your plugin should run once your theme is loaded by the WordPress. You can use the following code to do so:
function my_theme_is_loaded() {
// Bootstrap your plugin here
// OR
// try to run your function this way:
if ( function_exists( 'my_theme_function' ) ) {
my_theme_function();
}
}
// You can also try replace the `after_setup_theme` with the
// `init`. I guess it could work in both ways, but whilw your
// plugin rely on the theme code, the following is best option.
add_action( 'after_setup_theme', 'my_theme_is_loaded' );
What the above code does, is like you say to your plugin, wait until the theme is totally loaded, and then try to run my plugin code that rely on the theme code.
And of course, I suggest either wrap your theme function in a plugin function like that:
// This way, your plugin will continue running even if you remove
// your theme, or by mistake your rename the function in the theme
// or even if you totally decide to remove the function at all in the
// side of the theme.
function function_from_theme() {
if ( function_exists( 'my_theme_function' ) ) {
return my_theme_function();
} else {
return 0; // Or a value that is suitable with what you need in your plugin.
}
}
This is going to protect your site against theme de-activation or theme change. In this cases, you are going to have a plugin looking for a function in your theme, and while you change the theme or deactivate your theme, your plugin will break your site.
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.
How can I place a default text (hashtag) in the Custom Message?
The textarea is (located in line 643) under jetpack/modules/publicize/ui.php
I tried to put the text in front of $title in various ways, like:
<?php echo "#myhashtag $title"; ?>
or
<?php echo '#myhashtag '.$title; ?>
but it just echoes the text, not the $title.
Any ideas will be greatly appreciated.
You can use the approach of this Wordpress plugin i made (Publicize With Hashtags), which does exactly that. It basically use and action trigger bound to the 'save_post' native event.
If you want to develop your own one you can have a look at my Source Code on the project's GitHub page or in this installation & usage guide I wrote about it.
You can add a filter, like so, to your theme's functions.php or a site-specific plugin:
add_filter( 'wpas_default_prefix', 'add_default_publicize_hashtag_prefix', 10, 4 );
function add_default_publicize_hashtag_prefix() {
$default_tags = '#yourhastaghere ';
return $default_tags;
}
This will add your default hashtag before your title without you needing to hack the WordPress core.
jetpack/modules/publicize/ui.php itself states in its comments:
/**
* Only user facing pieces of Publicize are found here.
*/
You added your hashtag in the textarea which allows admins to enter a custom message (click edit and it will slide down with your hashtag).
As #Yazmin mentioned, the best way to permanently edit the message is using a filter. The filters available are wpas_default_prefix, wpas_default_message, and wpas_default_suffix.
Personally, I had no success using these filters and I'm interested in a working solution to this issue myself.