Use the second option. Adding anonymous functions as filters and actions is highly discouraged!!!
If you add an anonymous function in this fashion, it’s impossible to remove later on down the road by other plugins and code. So please, please, please don’t do that.
Related Posts:
- How do I use WP_query with multiple post IDs?
- Disable Attachment Pages Completely
- esc_attr() right way and use
- Get meta_id along with meta_key and meta_value
- Show content if parent page has children
- Detection of theme being used
- Where to include php files in wordpress and how to refer to them later [closed]
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- How to order posts by modified date without using ‘query_posts’?
- How to add a featured image to a existing post via php?
- Get widget settings function?
- wp_handle_upload_prefilter valid date from input file
- Mysterious HTTP 404 header in my own scripts
- Archive dropdown styling not applied
- Browser title script ignoring is_page /else conditional [closed]
- How to make custom total price reactive in navigation
- Adding tawk.to code just before body tag on functions.php file
- Custom php page outside the scope of my theme
- How to get 2 or multiple custom post types in wordpress functions.php
- Interrupting $html.= ‘ for IF statement
- Instantiate class to be available to all plugin functions
- Implement toggle switch for theme options in settings API
- Show comments menu in dashboard only if the site has comment
- WP nonce invalid
- Creating a Multi-Level Associative Object Using AJAX
- Create WP_Query to search for posts by their categories or their parent/child categories
- add_action shortcut?
- My custom wp-admin php files stopped working
- Trying to place a custom field after the total section in the checkout page in woocommerce
- Get page that displays all children of taxonomy parent
- WordPress default Search function inconsistent in WooCommerce Product Titles
- How WordPress reacts to a lack of memory of the server [closed]
- Function to capture a value and store it in a variable
- PhantomJS with wordpress
- My new button is in the wrong place
- Checking array against author id in loop
- Call to undefined method – Download Monitor
- Why does abstracting html from plugin code result in loss of access to wordpress functions?
- Show a different code on front page to other pages
- Make PHP work with HTML tags
- Admin ToolBar not being displayed at top of site
- Undefined method class::construct() when creating a plugin
- Why are the details of my todo not saving?
- Theme activation hook in php class
- How do I get an external php page to load using javascript
- Remove extract from function
- Undefined offset: 3 in custom function
- Redirecting to a custom forgot password page
- How to pass current loop data into nested loop
- How can I display Custom Post type Custom Columns and its Content in a Dashboard Widget?
- Proper way to use WordPress function with AJAX PHP file
- Custom navigation menu with awsAccordion
- Taxonomy term count
- phpMyAdmin error #1062 – Duplicate entry ‘1’ for key ‘PRIMARY’
- Replacing WordPress Icons (menu,icons32, etc)?
- WP insert post Redirect after function has executed
- Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
- add_action in namespace not working
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- Using a new WP_Query inside the loop
- How to Send Pingbacks for all Posts in WordPress?
- Featured image in menu wordpres
- Has a PHP update given me a 404?
- Replace background image with post thumbnail in shortcode
- Using A PHP App in WordPress
- HTML comment cause issue in functions.php script root
- Custom User registration system
- how to create a user rule that can only manage support tickets?
- Rewrite rule not working, but only when parameter is text
- How to prevent adding data to a localhost database after refresh?
- Generating 3 random numbers and saving them in database
- wp_ajax_ 400 Bad Request
- Trying to reload page with update_option_{$option} hook causing infinite reload
- WordPress Ajax filter: Create two loops for different output styles?
- How to display sticky post always at the top (before regular post) in wordpress?
- PHP warning with code for nav menu walker [duplicate]
- Error inserting into custom table – Object of class wpdb could not be converted to string [closed]
- Get the image title and alt from custom query
- How to Retrieve All Category Images on Front-End
- Showing wordpress latest post thumbnails in slider with auto increment
- media_handle_upload fails with gravity form submitted image
- how to display woocomerce description of each category in wordpress? [closed]
- My function echos only “array”
- Notify admin (by email) if post added with specific tag
- uploading a new theme to live server
- Display post from a category
- See output of a sql query while plugin installation in wordpress
- Shortcode Display From WordPress Dashboard Page Without Using post_id
- Warning: preg_replace(): Compilation failed: unknown option bit(s) set at offset -1
- How can I execute $string = if();? [closed]
- Send foreach $_post method to contact form 7 [closed]
- Null value given when confirming email’s
- Predefine Magazine Style Layouts
- WordPress online courses system
- How to align buttons properly [closed]
- index.php file keeps redirecting to a non-existent index.html file?
- How to pass parameter to another url?
- Displaying generated HTML within a WordPress site
- WordPress PHP8 Critical Error in class-wp-widget.php
- How to get the last date updated of postmeta?