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?
- WordPress and event-driven programming – what is it about?
- Where to get information about array fields in $_REQUEST?
- adding a filter to a shortcode?
- Variables declared in header not available in other includes
- Permanently remove first image from posts
- How to remove a metabox from menu editor page?
- add_filter to post-gallery and remove all ‘s?
- How to overwrite youtube embed?
- Rewriting search and pagination base
- Filter the blog title displayed in the header
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- body_class filter – Is there a better way to write this code?
- When would you use $_post instead of $post?
- Randomise upload filenames (or another solution to hide the original image URL from theft?)
- Setting up 2 SMTP accounts: 1 for wordpress and 1 for woocommerce
- How to rewrite URL with PHP variables with htaccess to a normal looking URL?
- How to pass arguments to add_action() or retrieve return value of called function?
- How can I Add a variable PHP in the Menu Nav
- Add data attribute to each li in menu
- 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?
- Don’t insert if permalink is the same?
- Unique icons next to each WordPress menu item
- PHP, Creating a dynamic variable
- Variable not staying set
- Apply class to every third list item? [duplicate]
- How to catch wordpress post ID when it’s published
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- Insert page content into another page with a changed variable
- How to access or parse key/values that have “string”
- How do I create a secondary version of the_content
- how can I include some custom variable from functions.php?
- Add a custom class to the body tag using custom fields
- How to pass hook variable to function?
- WordPress doesn’t load HTML
- WordPress is removing query variables like page, p from the URL of a custom static page
- Show related products by attribute based and certain conditions
- How to Create custom block for displaying information in content section which act like shortcode
- How do I add a function to parent theme
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- Filter ‘comment_notification_text’ not working
- How to remove get_header From all single pages in wordpress with functions.php without plugin?
- Use wp_head hook on template page
- Change the “Show All” button in a WordPress Portfolio Filter
- Custom global variable not working in function
- Adding custom field to product category and show it to shop/category shop page
- Change lost password url to a mailto URL in WordPress
- Remove span tags from WooCommerce Downloads page
- Add a top bar to a wordpress theme without editing the header.php file?
- Get original value in save_post action hooka
- How do I fix Undefined variable using $_POST in function?
- Register/enqueue scripts only on certain admin pages
- Help hooking into user_register
- dynamically change content of div with php
- How can I move the posted-on date above the post and below the entry-header?
- Where can I find the declaration of `$_wp_theme_features`?
- Post formating on Home page
- calling a function from a class in your template
- Search box background on a different page template
- If I define a variable in header.php, how do I make it available to templates?
- How to filter part of a variable if it is no array?
- Use ajax response in PHP function
- Add/alter image attribute before render
- Passing value from one hook to another
- How to pass value to add_filter wpcf7_form_tag from another function?