77

You need to use the right hooks (which are not always the same as the URLs/slugs), and it doesn't hurt to use a hook that runs later (e.g., admin_init): add_action( 'admin_init', 'wpse_136058_remove_menu_pages' ); function wpse_136058_remove_menu_pages() { remove_menu_page( 'edit.php?post_type=acf' ); remove_menu_page( 'wpcf7' ); } You can use ...


67

When you visit a frontend page, WordPress will query the database and if your page does not exist in the database, that query is not needed and is just a waste of resources. Luckily, WordPress offers a way to handle frontend requests in a custom way. That is done thanks to the 'do_parse_request' filter. Returning false on that hook, you will be able to ...


62

You can enable WordPress logging adding this to wp-config.php: // Enable WP_DEBUG mode define( 'WP_DEBUG', true ); // Enable Debug logging to the /wp-content/debug.log file define( 'WP_DEBUG_LOG', true ); you can write to the log file using the error_log() function provided by PHP. The following code snippet is a very useful function wrapper for it, make ...


43

Object cache everywhere WordPress tries to reduce the number of database queries as much as possible. For example, anytime you get a meta field or a taxonomy field, before querying the database, WordPress looks if that that was already queried and stored in cache, and returns it from there instead of querying the database. The "cache job" is done via ...


39

Well the second bit of code is technically the correct way to do it. However, at the end of the add_settings_field() you can pass arguements. Please view the WordPress Add_Settings_Field function reference. This will help you in getting the best understanding of how the add_settings_field() function really works. Now, with that said, you could use a '...


38

The easiest way would be using get_post_field(): $post_author_id = get_post_field( 'post_author', $post_id ); For more details on this issue: have a look at this StackOverflow answer.


36

For 2018 and onwards users: Since WordPress 4.9.0 there are new filters you can use for this (no need for a plugin anymore): wp_new_user_notification_email - customise email sent to User wp_new_user_notification_email_admin - customise email sent to Admin Usage example on email sent to Admin (you can paste this in your theme's functions.php ): add_filter(...


36

It's stored in the database, within the wp_posts table, under the custom_css post type, where the post name is the theme slug. There you also have the related customize_changeset and revision post types. The custom css post ID is also stored in the wp_options table under each theme mods, e.g. theme_mods_twentysixteen for Twenty Sixteen. It's informative to ...


33

WordPress 3.9 introduces a theme_page_templates filter. The example below from a Twenty Fourteen child theme functions.php shows how to remove the "Contributor Page" template: function tfc_remove_page_templates( $templates ) { unset( $templates['page-templates/contributors.php'] ); return $templates; } add_filter( 'theme_page_templates', '...


30

As an extension to @G.M. answer (which is the only possible way to do this), here's a slightly shortened/beautified and and an extended version (which I personally prefer): Shortened/Beautified variant It's enough to do a boolean check for the contained value. If it's true, the result will be (bool) true, else it will be false. This produces a one case ...


29

The question was for Wordpress 3.0, but just in case someone has the same question for a more recent version, from Wordpress Codex: "Starting with version 4.1, meta_query clauses can be nested in order to construct complex queries." https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters So, that query should work on ...


29

Most of the following can be found in the Codex: apply_filters The callback functions attached to filter hook $tag are invoked by calling this function. This function can be used to create a new filter hook by simply calling this function with the name of the new hook specified using the $tag parameter. $value = apply_filters( $tag, $value, $var_1, $...


28

Since WordPress 3.5 this option (XML-RPC) is enabled by default, and the ability to turn it off from WordPress dashboard is gone. Add this code snippet for use in functions.php: // Disable use XML-RPC add_filter( 'xmlrpc_enabled', '__return_false' ); // Disable X-Pingback to header add_filter( 'wp_headers', 'disable_x_pingback' ); function ...


25

I for myself use a combination of: one file dedicated to the one-time script using a transient to stop the script from accidentally running more than once using capability-management or user-control to ensure the script is just run by me. Structure I use a file (onetime.php) in my include-folder inc, which is included in the functions.php, and deleted ...


25

You could do this using the WordPress uninstall.php support: <?php if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) exit(); global $wpdb; $wpdb->query( "DROP TABLE IF EXISTS NestoNovo" ); delete_option("my_plugin_db_version"); ?> This uninstall.php file is called when your plugin is deleted.


25

style_loader_tag style_loader_tag is an official WordPress API, see the documentation: https://developer.wordpress.org/reference/hooks/style_loader_tag/ apply_filters( 'style_loader_tag', $html, $handle, $href, $media )Filters the HTML link tag of an enqueued style. First enqueue your stylesheet, see documentation: https://developer.wordpress.org/...


21

This is a very faceted issue. It combines inherent HTML content issues with whole new load of translation challenges, such as scanning for strings, translation process itself, and its verification. So we have to combine: Text (in translatable form) HTML markup (in hard to break, but preferably flexible form) URL destination (in secure and preferably ...


20

Is it safe to directly delete all rows in the wp_posts table that have a post_type of revision? (I've seen conflicting answers on this—but I'd love to be able to just do it this way if it's safe) Safe, it's safe. If there is only one user (you) that can edit posts on the site it's safe and does not cause any other problems. If there are more users, ...


20

The add to cart template is only 1 of the many things you'll need to do. Each product type has it's own class in the /includes/ folder. Each one extends the WC_Product class. To add items to the list you've screencapped (which is on the admin side and not the front-end, unlike the add-to-cart.php template, you will need to filter product_type_selector. ...


20

You can also do this: run onetime.php and rename it after execution. if ( current_user_can( 'manage_options' ) ) { if( ! file_exists( '/path/to/onetime.php' ) ) return; add_action( 'wp_footer', 'ravs_my_onetime_function' ); // execute my function on the desired hook. } function ravs_my_onetime_function() { // all my glorious one-time-...


20

You probably need to set the add_action priority to a higher number and target those two new links specifically like so: add_action( 'admin_menu', 'my_remove_menu_pages', 999 ); function my_remove_menu_pages() { remove_menu_page( 'edit.php' ); //Posts remove_menu_page( 'upload.php' ); //Media remove_menu_page( 'edit-...


19

Use the filter update_option_{$option}. It runs after a successful saving. $option is the name of your option, and you get the old and the new value as parameters. From wp-includes/option.php: do_action( "update_option_{$option}", $oldvalue, $_newvalue ); Use it like this for an option wpse_themesettings: add_action( 'update_option_wpse_themesettings',...


18

The only valid answer: IMPOSSIBLE So many high voted answers.... time to set the record straight. Well, the truth is that it is virtually impossible and even if it is,life is probably too short to put an effort into it. Any answer, that promotes steps to hide WP is just a waste of your time and will mislead you thinking that you are hiding your WP (that is ...


17

This plugin demonstrates how to do it. Of note, the steps involved are: Register each setting to update/change When creating the control, pass an array as the setting argument When rendering the inputs, pass in the settings key to link and value The settings key is not the name of the setting, but the indices of the array, e.g. 0, 1, 2 Access the settings ...


17

Improve your conditional to include a check for post type being queried. It can be done via WP_Query::get method So, where you have if ( !is_admin() ){ $query->set( 'meta_key', '_ct_selectbox_52f65ae267764' ); $query->set( 'meta_value', $city ); return; } replace with if ( ! is_admin() && in_array ( $query->get('post_type'), ...


17

// PLUGINS THAT ADD AS DASHBOARD SUBMENU // IF THIS IS THE URL BELOW - THE PAGE VARIABLE IS WHAT I NEED ( SO WHATEVER COMES AFTER PAGE= ) // http://example.com/wp-admin/index.php?page=iconize-plugin-update-notifier remove_submenu_page( 'index.php', 'iconize-plugin-update-notifier' ); // OR FOR EXAMPLE WOOCOMMERCE DASHBOARD SUBMENU ...


17

I don't think there exist one, but you could create your own, wpse_empty_trash, with something like this: /** * Add a custom hook 'wpse_empty_trash' */ add_action( 'load-edit.php', function() { add_action( 'before_delete_post', function ( $post_id ) { if ( 'trash' === get_post_status( $post_id ) && ...


16

add_action('admin_menu', 'my_remove_sub_menus'); function my_remove_sub_menus() { remove_submenu_page('edit.php', 'edit-tags.php?taxonomy=category'); remove_submenu_page('edit.php', 'edit-tags.php?taxonomy=post_tag'); }


16

Maruti Mohanty’s suggestion is not bad, but it will fail. There are many core actions with a higher priority: wp-admin/menu.php: add_action('admin_menu', '_add_themes_utility_last', 101); wp-includes/admin-bar.php: add_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); wp-includes/canonical.php add_action( 'template_redirect', '...


16

Is easy to use 0 and 1 values and then typecasting inside the function: [shortcode boolean_attribute='1'] or [shortcode boolean_attribute='0'] but if you want you can also strictly check for 'false' and assign it to boolean, in this way you can also use: [shortcode boolean_attribute='false'] or [shortcode boolean_attribute='true'] Then: add_shortcode( '...


Only top voted, non community-wiki answers of a minimum length are eligible