The problem is global $post
.
As @Pieter suggested global $post
object can be alter anytime with some other plugin or code. Menu items are effected because global $post
does not contain the correct object.
Instead of $post
, the_title
filter also provide you ID of current post in action, so use it in this way
function append_album_review_to_title( $title, $id ) {
if ( get_post_type( $id ) == 'album_review' ){
return 'Album Review: ' . $title;
} else {
return $title;
}
}
add_filter('the_title', 'append_album_review_to_title', 10, 2);
Related Posts:
- Passing a parameter to filter and action functions
- Get a list of all registered actions
- How can I edit post data before it is saved?
- Where is the best place to use add_filter
- How to only hook on Single.php after content?
- Use external link in the add sub menu
- Very stubborn wp_register_script / add_action vs remove
- do_action and hook methods
- How to filter content post only on save
- Filter or action hook to insert content on admin pages before tag
- What is the purpose of $merged_filters?
- How do action and filter hooks understand where to look for the core function that we hooked our function to them
- How to check current user before all actions and filters?
- Get Time Taken By Each Action Hook in WordPress
- Plugin developer automated documentation
- Is there a hook to Intercept al urls from a webpage and redirect to a page
- WordPress user account activation
- External Script Using WP – Hooks / Actions Not Working?
- Is there a way to figure out which action/filter invoked a function?
- Using add_action before add_filter on a plugin?
- remove_action not removing add_action from constructor
- Editing wp-config.php
- How to use add_action for multiple instances of the same class
- How to hook into action/filter call
- How to append new form elements in “Add New” form of Users in WordPress admin panel?
- Edit post image attributes on fly?
- How to Unhook actions/filters in within Class in plugin
- Nested Actions and Filters
- Use action, filter, or hook to append HTML to WordPress plugin function
- Remove action added in plugin class from theme
- Help needed with woocommerce (wc stripe) filter
- What action or filter can I use to change all the html returned from server for a page?
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Passing a parameter to filter and action functions
- change output location of plugin function using a custom hook
- Filter for modifying image on upload
- Which filters or actions involve with index page for plugin?
- add query string to all pages after user logged in
- Which action/filter can i use for a Member Plugin [closed]
- wp_head filter not executed inside custom class
- How to customize WP_Error (REST JWT authentication plugin) [closed]
- Custom plugin init action causing general slowness
- Output content to the_content before a plugin does
- add_action in static class [closed]
- URL parameters causing 404 on home page, but nowhere else
- Which filter affects the ‘entry-title’ post class
- How to change the name of the “edit my profile” link in the WordPress admin backend
- Filtering get_permalink in Jetpack / ShareDaddy
- Submit custom form from post content and execute in plugin
- Inject HTML meta tag inside wordpress tag using add_shortcode
- Proper way to replace the_content only for pages created by custom plugin
- add_filter doesn’t work
- How to get post ID with hooks publish_post, new_to_publish, etc
- add_action in a custom plugin
- register_activation_hook in oop approach
- Redirect to another page using contact form 7? [closed]
- What is @Action in WordPress?
- Problem with removing plugin action
- edit_user_profile and show_user_profile are not firing inside a class
- Template filter for custom taxonomy terms
- Add action to fire when a published post is updated
- do add_action on condition
- get gravity form ID from backend/wordpress admin
- How to pass variables to a function argument using add_action [duplicate]
- _prime_post_caches in wordpress
- How to trace SUBMIT button
- How passing values to construct function with Actions?
- Remove_action from plugin with a Class
- Add sub menu page in your plugin
- add_action into another add_action not working
- publish_post action doesn’t work
- Run a plugin just ‘once’ per page reload
- Check if variable is set in filter
- What exactly happens to function argument availability when using a filter?
- a weird attribute on every html tag
- Submit Form data to another page via Ajax (WordPress Way)
- the_post hook is not firing for me
- Why do plugins often ask to add in to templates?
- Does using `add_action( ‘init’…` cause performance issues?
- do_action Nested List
- Passing stored variables to add_filter
- Modify page title and subtitle with a plugin
- override filter in a plugin
- Check filter defined or not?
- Create a post builder skin in a plugin
- Plugin Development – Functions or Hooks?
- How to get menu location in wp_update_nav_menu hook
- How do I add some javascript validation to the admin interface form’s onsubmit?
- Basic function call on init failing
- How can I apply a WP filter on specific plugin version
- How to create Admin Notice from Plugin with argument? [duplicate]
- Hook for page Request?
- Are there action hooks for comments?
- Trying to add a page template for my custom post type from a plugin, but it will not display in the template dropdown unless file is in theme
- How to use the pre_option filter before a plugin loads?
- New bulk action to resend welcome emails
- Change text string in a plugin
- WooCommerce: after install hook
- How to use filter to disable adding a product to wishlist?
- correctness of URL