New answers tagged

1

The docs for register_nav_menu show an example using the after_setup_theme hook so I would use that. after_setup_theme This hook is called during each page load, after the theme is initialized. It is generally used to perform basic setup, registration, and init actions for a theme. ...the after_setup_theme hook, which runs before the init hook. The ...


2

First off, you should not register functions loose in functions.php because you cannot remove them (using remove_action). It can also cause debug errors since WP may not yet be stable. By using a hook you are making sure WP is stable enough to run your code, and what you need to use has been loaded. Check out the answer on the Wordpress Forums for more info ...


1

You can use them the moment they are available i.e. as soon as functions.php is loaded, hence why you've seen so many different options. I would recommend sticking with the "defacto" way - using the hook after_setup_theme


1

This question has been answered on Stack Overflow before: http://stackoverflow.com/a/14626254/844732 add_action( 'admin_head', 'check_page_template' ); function check_page_template() { global $post; if ( 'page-homepage.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) { // The current page has the foobar template assigned ...


3

They were both introduced in version 2.9, but were done so in different files. update_postmeta went into /wp-admin/includes/post.php While... update_{$meta_type}_meta went into /wp-includes/meta.php It was only later that update_postmeta was shifted into /wp-includes/meta.php. So I believe it was for backward compatability, where by because the ...


0

You should not use any hook before wp_loaded unless it performs some initialization, or required for user authentication, therefor the earliest is wp_loaded


0

As @Milo pointed out in the comments above, custom post types and taxonomies are registered on init, so this would seem to be the earliest hook available that is guaranteed to work for all content.


-1

This works for me. I am using WP-Members plugin (and hook). add_action( 'wpmem_post_register_data', 'my_registration_hook', 1 ); function my_registration_hook( $fields ) { wp_set_current_user( $fields['ID'] ); $creds = array( 'user_login' => $fields['username'], 'user_password' => $fields['password'], 'rememember' ...


0

I tried to update the image size with: add_image_size( 'medium_large', 600, 255, array( 'center', 'top' ) ); But when i update the image size with height, width and crop, wordpress is just using the "large" image-size. When i just use add_image_size with the width argument: add_image_size('medium_large', 600, '', true); The image size gets updatet to ...


1

to see list of functions or actions hooked to a particular action hook you can use the following code. global $wp_filter; echo '<pre>'; var_dump( $wp_filter['wp_head'] ); echo '</pre>';


0

You can call add_image_size() again to update the existing image size. Assuming it is called medium_large (Events Manager Pro is a paid plugin so not very much people have it) you can do something like: <?php function update_medium_large_size_wpse216595() { add_image_size( 'medium_large', 600, 255, array( 'center', 'top' ) ); } add_action( 'init', ...


0

json_prepare_post should be rest_prepare_post or rest_prepare_{post_type}


0

The solution that I used was the following: add_action('my_action', array(&$this, 'classFunctionName')); When scheduling I used the following: wp_schedule_event(time(), 'daily', 'my_action'); So the classFunctionName is triggered on a daily basis and it is called from within the plugin class.


0

This reason, and others (removing a hook for example) is why you should use for hooks only plain functions or static functions. OOP in plugins and themes rarely has anything to do with proper OO. If you use it as a way to have a separate namespace, then just use a namespace.


0

You want to disable the option to delete, If you mean the delete button on the user list at /wp-admin/users.php you can use user_row_actions class to hide the 'delete' link with below snippet: add_filter( 'user_row_actions', function($actions, $user_object) { $result = new WP_Query( array( 'author'=> ...


1

The add_rewrite_rule function doesn't change the database. Just an array in memory. It is not an expensive operation. The alternative is to add code to detect whether your rule is there, which is actually more expensive than just modifying the array.


0

While Pieter solved the issue elegant and comprehensively with no doubt, I finally went with another solution, which I want to share here, too. Maybe some folks are facing similiar issues in the time to come. For custom post type definition as described in my question I used a plugin called Pods. As the plugin devs and community are likely to handle custom ...


0

When you click on "delete", the action 'delete_user' will be launched: https://core.trac.wordpress.org/browser/tags/4.4.1/src/wp-admin/includes/user.php#L313 After that you can check, if the user has written at least one 'portfolio' post. add_action('delete_user', 'sw_portfolio_check'); function sw_portfolio_check( $user_id ) { $result = new ...


0

Create a blank page and name it panel then go to your created signup template and select parent page panel. Its just below Publish->Page Attributes. /*Add noindex to this page (Add to functions.php)*/ function add_noindex_tags(){ # Add noindex to page. if( is_page('panel') ) echo '<meta name="robots" content="noindex,nofollow">'; } ...


0

In the end i used this- // Define global variables global $am_globals; $am_globals = array( 'if_autoload' => get_option( 'autoload-or-shortcode' ), ); and this- if( ! $if_autoload = $GLOBALS['am_globals']['if_autoload'] ) {


0

Save yourself a headache and make a class. The static variable can be accessed like a global once it's loaded. Just be sure the class exists before you try to use it! if ( ! class_exists( 'WPSE_20150123_Plugin' ) ) { class WPSE_20150123_Plugin { // our variable that will be set and read back later public static $if_autoload = 'I\'m Not ...


0

Also the way you are calling your function is incorrect : <div><?php echo $get_number_of_promos(); ?></div> You are calling a function (get_number_of_promos) as a string ($). It should be : <div><?php echo get_number_of_promos(); ?></div>


1

I had time to look at your issue and the options-reading.php page which is the template used to render the reading settings page in backend. There are unfortunately no filters to filter or add custom posts as sticky posts in a selectable dropdown. There are two hidden filters though which we can use, they are wp_dropdown_pages inside the ...


0

Use php Anonymous functions: $my_param = 'my theme name'; add_filter('the_content', function ($content) use ($my_param) { //$my_param is available for you now if (is_page()) { $content = $my_param . ':<br>' . $content; } return $content; }, 10, 1);


0

An important difference from the_content() is that get_the_content() does not pass the content through the 'the_content'. This means that get_the_content() will not auto-embed videos or expand shortcodes, among other things. If you find yourself annoyed with formatting of the content, more specifically the added p-tags that WordPress puts into the content ...


0

I ended up inserting the payment description. (the one you specify in the woocommerce settings in the Wordpress backend) The "native" build-in woocommerce payment-text is static and doesn't relates to the actual selected payment method. :-( I did this by modifying the woocommerce template file: 1: Copy this template file: ...


0

Create a function with the needed arguments that returns a function. Pass this function (anonymous function, also known as closure) to the wp hook. Shown here for an admin notice in wordpress backend. public function admin_notice_func( $message = '') { $class = 'error'; $output = sprintf('<div class="%s"><p>%s</p></div>',$class, ...


0

The way I've done this was to take a copy of content-product.php and paste it into the root of your theme folder. Comment out do_action( 'woocommerce_before_shop_loop_item_title' ); and do_action( 'woocommerce_after_shop_loop_item' ); Quick and dirty, but it worked for me.


2

It really just depends on what you need to do here. The general method is to hook all your theme support features to after_setup_theme for some obvious reasons. after_setup_theme is the first action hook available to themes to add any type of support the theme. Certain features has to be registered here and cannot be registered later. One feature that ...


1

Unfortunately there is no hook available to remove that "Our Bank Details" text. But, you can hide the default which is added and un-intended area by placing following rule in your theme's style.css file: .woocommerce-order-received .woocommerce h2:nth-of-type(2) { display: none; } Then to have "Our Bank Details" at intended place, simply go to ...


2

If you want to redirect, a good event to use is template_redirect: add_action( 'template_redirect', 'my_page_template_redirect' ); function my_page_template_redirect() { // You can skip is_user_logged_in() if checking the user capability if( is_page( 1234 ) && ! current_user_can( 'do_something_special' ) ) { $redirect_to = ...


0

Thanks, will do next time. I figured this one out: function my_custom_wc_api_order_response( $order_data, $order, $fields ) { $customer_info = get_post_meta( $order->id, '_customer_info', true ); $order_data['payment_details']['customer_info'] = $customer_info; // Apply filters if necessary if ( $fields ) { $order_data = ...



Top 50 recent answers are included