After doing some playing around, I discovered this can actually be accomplished by defining the name of the hook I want to add the filter to via a variable.
So if my $post_type_name
is portfolio
and my $box_id
is piece_info
, I can make a filter as follows:
function add_meta_box_class( $classes ) {
array_push( $classes, 'custom-class');
return $classes;
}
$filter_name="postbox_classes_" . $post_type_name . '_' . $box_id;
add_filter( $filter_name , 'add_meta_box_class' );
This will result in a filter being created using the postbox_classes_{$page}_{$id}
hook as postbox_classes_portfolio_piece_info
.
Related Posts:
- Change the footer text on the login page
- How can I hook into and edit the text of a wp_nav_menu tag?
- Check if page parent has certain template
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- How do I know what variables are passed in a filter/action and what their meaning is?
- Find variables available at a given hook
- Getting my head round WordPress filter
- How To Change The Html of Products filtration sidebar in Woocommerce?
- How to set a custom path, for ajax image upload folder in admin?
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- When using the_author hook, how can I determine the PHP file that generates each call to `the_author()`?
- How to call function at the bottom of post using plugin?
- Handling Body class based on Template
- Edit incorrect password message WordPress
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Remove a div from RSS feed
- How to add an arrow to menu items has submenus
- WordPress Gravatar filter is removing my custom attributes
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Get access to variable from previous pageview, excluding ajax-calls
- How to have different site identity logos on each page on Astra Theme [closed]
- Dynamically adding filters
- Must filter functions receive all arguments passed to them?
- How to sort WooCommerce products page by latest in-stock items first?
- Filter wordpress posts without searching the keywords in the post content
- Variation prices breakdown only for single product page
- How to edit post meta data before publishing the post it self wordpress?
- Fatal error: Uncaught Error: Class ‘WP_Block_Styles_Registry’
- using filter and hook inside class
- add_filter() inside another add_filter()
- How to add custom checkout field in user details mail template
- For each loop will not append to the_content hook
- Assign new post author IF another user in custom field on post transition
- Is there a hook that I can use when a fatal error occurs?
- how to append ACF field data using one of the following filter/ hooks
- Pass variable from one function to another
- Get value from shortcode to do something
- How do I add custom bulk actions to multiple custom post types?
- Add data attribute to each li in menu
- Show prices with tax in Woocommerce Mini Cart [closed]
- Ajax category filtering products default show all
- Add a specific part of current category page url to shortcode
- Why does my callback function not work with this custom filter hook?
- Reload part of checkout on changed shipping method
- Trying to build simple deposit code that hooks into woocommerce
- Removing “wpautop” (auto tags) only on certain pages?
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Remove metabox from WordPress menu editor page?
- Add a product to checkout via form
- Add filter when image is uploaded?
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Why ajax doesn’t work on certain wordpress hooks?
- Remove the first 5 characters of the_title and orderby that
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- Print last modified date only on posts
- user_profile_update_errors hook not executing
- Set meta field to publish date + 2 weeks
- Error in custom php function doesn’t exist
- Don’t insert if permalink is the same?
- Return a numerical function value in Customizer controls
- Adding widgets to my plugin page instead of WordPress dashboard
- Unique icons next to each WordPress menu item
- PHP, Creating a dynamic variable
- How to modify a global variable in a function and use it on another function?
- edit_comment_link is not showing for comment author
- Adding function to Genesis genesis_header [closed]
- Modify custom field input data before creating a new post
- how to make custom ajax handler?
- Are all hooks/functions tied to Kses meant for sanitization?
- Change tinyMCE editor to allow marked content when pasting from Word
- Problem with login form
- Alter required message using comment form api
- How to debug this search & replace strings snippet?
- Why does wp_head hook my functions to the beginning of my source code?
- Pass argument to event hook
- Hide Featured Image Meta Box on Editor Screen
- Add item to top of menu using a filter in functions.php
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- Should `wp_login` be used since it’s deprecated?
- Add filter multiple times using only one master function
- Variable not staying set
- How to edit php code in WordPress Post file?
- Change page title from page using php via php executed from page/post itself
- How to make modifications only to certain elements of an HTML string on the server-side?
- Override a function defined in wp-includes/comment-template.php
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- Password minimum length in personal subscription [closed]
- How to use a custom hook
- Run a code only on theme activation only during first activation
- Theme activation hook in php class
- Filtering a function’ output for a new continued function
- WordPress function and string as variable?
- Create a WordPress shortcode using PHP [duplicate]
- How to pass a PHP $_GET variable and fetch/output it?
- Creating WordPress Shortcode with Variable
- Deleting Certain terms from appearing on the front end as links
- Theme not calling Jquery properly
- How to put a form with php code into a variable or shortcode?
- Content filter won’t work
- Apply class to every third list item? [duplicate]