It’s important to always return the value in filter callbacks, otherwise it’s like adding the __return_null()
callback.
Here’s an example that adds the blog
class only to page with ID 40:
add_filter( 'body_class', 'add_blog_to_body_class' );
function add_blog_to_body_class( $classes )
{
if ( is_page( 40 ) )
$classes[] = 'blog';
return $classes;
}
Related Posts:
- the_content and is_main_query
- Apply the_title filter to post titles AND backend auto social-sharing plugin, but not nav menu
- Filter out some plugin action in wp head / wp_footer
- Using Conditional Statement in functions.php
- Same Conditionals Not Working on Two Different Hooks
- Redirect to checkout woocommerce failed
- Remove CSS & JS files from WordPress Main Page For Increase Pagespeed?
- How should I be using filters and is_single together?
- Is there any reason for the nested filters to be applied on the first case and not in the second one?
- adding an action inside if condition not working
- The title of an attachment is not working
- is_page_template() doesn’t work with excerpt_length filter
- Add a filter conditionally based on frontpage
- Add custom options to the wplink dialog
- How to show page content in feed?
- remove_filter( ‘the_content’, ‘wpautop’ ); only for certain post types
- Valid characters for actions, hooks and filters
- How can I add information underneath the user’s name on the users.php page?
- Is calling function_exists() faster or slower that apply_filters()
- Filtered query_vars becomes global. Why does this work?
- AJAX filter posts on click based on category
- Can I add custom meta for each image uploaded via media-upload.php?
- Alter only the page title, not the post titles within
- Load different template file when condition met?
- Some questions regarding filter
- Problem getting single_template filter to work – I want to serve a different single.php file for posts in a certain category
- Too many actions/filters!
- How can override a add_filter of a plugin?
- How to check a filter are applied
- How do I add a listbox to the TinyMCE editor?
- How to remove google font in WordPress for only single page?
- How do I filter get_the_excerpt() but keep all of its functionality intact?
- Overwrite default WordPress wording
- Why anything done on comments_array hook gets reset?
- Wrap h1-h6 in a div
- add filter login_redirect does not contain original requested redirect
- get_header and hook avoid normal call
- Dropdown filter in custom posts
- How to order by taxonomy using wp_query
- Filter taxonomy admin pagination
- Feed, RSS not able to clear the cache and cannot change the limit of cache life time
- WP action/filter to modify title before header output and article output?
- Custom view counts not updating correctly
- WP Filter to change the URL of an Anchor wrapping the last gallery image
- Gutenberg – Add align controls to a custom block
- To add a custom filter based on a meta field
- I can not include page to wordpress function add_filter, the_content
- How to create Woocommerce Product Filter Widget [closed]
- Add default user field to WooCommerce checkout [closed]
- Filtering Comment Reply Links (comment_reply_link_args) for “infinite replies” in nested comments
- Create Search Form to Filter Through Terms
- Upload restrictions – upload_mimes – filter: Adding multiple MIMEs for a single extension and adding multiple extensions for a single MIME type?
- Filters on Login Page
- How can I change the email that is inside the default email texts of wordpress?
- How to filter link?
- Conditional does not work with add_filter
- Modify message displayed on post save
- Pass debug_backtrace() in WordPress filter
- Set “woocommerce_is_purchasable” to false for specific “$product->is_stock_status”
- How to edit embed filter for youtube video to allow responsive full width layout
- How to access page variable inside action hook
- I need to hook and change language of facebook sdk
- change “missing attachment” text functions.php
- Use has_filter on comment_post
- Shorten the title length
- Problem with Class, Filters and Callbacks
- Renaming wordpress login and get new password button
- preg_match() not working with post content
- Search a title word through query_posts (not the exact match)
- Parse a shortcode differently based on on what it’s nested in
- Elementor Image Hover + Filter Grid [closed]
- How to redirect template_directory to subdomain relativ url?
- How do I add tags to entire comments, not just their text
- Scanning for custom embed and prefetching
- How to exclude or include categories in wp rest API without query parameters?
- Remove and replace woocommerce add to cart button [closed]
- add_filter( ‘the_title’ gets through this if statement twice
- Changing the category for existing Gutenberg blocks
- Replace a specific URL on all apperances on the Website (Maybe a filter?)
- Modify WordPress Page Title ()
- How to add lazy field in content endpoint using Gutenberg blocks
- how to use apply filter for Class?
- How can I see exactly what arguments are being passed through a filter so that I may modify them?
- Modify WordPress search behaviour in backend?
- Re-order search results with posts_orderby filter and post meta value
- Set Microsoft Word links to open in new window/tab
- WordPress get_avatar filter to match logins
- ‘the_content’ Filter delivers empty string with lengh (608)
- Testing requested query in pre_get_posts
- Output dynamic_sidebar_params in wp_head
- How to sort posts according to meta value?
- Modify WooCommerce email shipping text value
- Change shortcode output (filter?)
- How do I add a class to all sidebars to let a Google Custom Search Engine know not to index the content?
- Updating User Profile on Registration
- remove_filter excerpt_more from a plugin class
- Why does using excerpt_more filter change link location?
- Can you call a filter hook by “add_action”?
- Why isn’t this add_filter function working as expected?
- Adding filter to the Contact Form 7 response