I believe your the simple nature of your example may have led to a misunderstanding of the way appy_filters() would operate. There is a great article that really explains how to use add_filter() and apply_filters() well, using very readable examples.
Basically, the problem appears to be that your code declares add_filter() AFTER you define it with add_filter(). This is an “order of operations” error.
Perhaps this annotated version can help:
// declare your filter function and callback .. usually pretty close to each other.
add_filter('ex1_append_text', 'callback_appender');
function callback_appender($initial_text){
return $initial_text.' ... whatever ...';
}
// setup basic variable, as you did
$var="testing";
echo $var;
// apply the filters we declared above
$modified = apply_filters('ex1_append_text',$var);
echo $modified;
Related Posts:
- Difference Between Filter and Action Hooks?
- How many times will this code run? (or, how rich is grandma?)
- add_action hook for completely new post?
- WordPress Hook for user register
- Using filters and actions for plugin API?
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- What’s the earliest point I can get the queried object ID?
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- Call activation hook multiple times
- What’s the difference between hooks, filters and actions? [duplicate]
- Two-step login process – Is it possible?
- How to check if certain plugin exists and in expected version
- Plugin development, hooks, generate content
- Hook event for upload image in the menu
- Help with callback using do_action_ref_array
- Define a function outside a class and call the function using action or filter hook
- Is it possible to modify the media library admin screen?
- What function to hook for changes made in status and visibility of a post
- Synchronize Custom post type tags to WordPress default posts tags
- Order of Operation for these three hooks
- Modifying values with add_action to be sent to db
- Woocommerce – Hide a Column in Cart Table
- save_post hook not triggered in WP v3.6.1
- Hook into theme-switching later than `setup_theme`
- Hook to get image filename when it is uploaded
- How to display a message about updates in the plugin list
- How to delete an user including data from custom database tables
- Act on user meta updated, but only once
- Should action callbacks start with a verb?
- Execute Hook on the footer or header after activating a plugin
- Why is my javascript not invoked in my hooks except wp_head?
- Namespaced action and filter tags
- What filter should I use to insert a button inside on Media>Add New
- get_current_screen() return null
- how to add custom functionality after woocommerce place order button
- How to use a hook to override an update_post_meta call in a plugin?
- External Authentication, session_tokens not destroyed on logout
- Conditional hook based on the core function that is calling it
- correct way to call javascript into hook function
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- Send push when new post is published in a certain category
- WordPress custom taxonomy check box to dropdown
- Force HTTPS 301 redirect with hook
- Add a new confirmation page before saving
- use of do_action() without any functions attached
- How dynamic action login_form_{action} is working
- What happens when two or more plugins use the same hook?
- How to get all queries’s results after they have executed?
- flush rewrite rules after plugin update?
- Add child pages to submenu automatically
- After plugin activation hook
- Odd map_meta_cap $args on post edit — sometimes integer, sometimes string
- How can I create a custom plugin that allows anonymous users to signup without registering?
- hook filter after the_content on a specific page
- Bind a function with its own argument to show something dynamically after every content
- What’s the hook for filtering every texts of site?
- Hook add_attachment error
- Associate multiple email addresses with the same user account, so they can log in with either
- Run command “composer install” when activating wordpress plugin
- Update variable value via add_filter
- Configure WordPress to Generate Scheme-less Relative URLs
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- Ajax +wordpress onClick link redirect to new page and create html content
- How to replace settings in WordPress plugin from a theme
- Creating posts with links from a txt file
- Action / Hook when a new plugin is added
- apply_filters() and call_user_func() to define and call a function outside a class
- Getting Post ID at “stylesheet” and “template” hooks
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- Woocommerce get_term_by() in transition_post_status hook doesn’t works
- Limit get_next_post to posts from the same author
- Any way, hook to add content right before the “read more” link?
- Is there any way to get post meta from publish_post hook?
- How do I ensure I can loop through every enqueued script and CSS?
- Problem in plugin debuging in wordpress
- OOP development and hooks
- Plugin Development – Call to undefined function comment_exists()
- Add_action not calling callback function
- Prevent plugin activation and add admin notice
- Unable to show a message after plugin activation
- Function not working on any file other than the main plugin file
- Does WordPress have something like timer hook?
- Multi hook deploiement
- Can I use a hook other than ‘init’ to handle form submissions?
- Template file structure , wordpress hook for altering the template
- woocommerce single product page hook not working
- How can I set a dynamic value for post_updated_messages based on return value of post_updated?
- What is the use of wp_schedule_event hook?
- How do I replace title with my plugin?
- Looking for Hook that is fired after a plugin or wp upgrade is installed/updated
- Woocommerce: block user removing cart item
- How can I get a plugin to hook ‘dbdelta_queries’ — a filter used during version update?
- Send retrieve password notification email with custom HTML email template
- wp_head is not fired from the hook I have used in my plugin
- Ninja Forms: Front-End Forms, Post ID?
- Execute callback after REST API request completes + Response is sent
- How to customize password reset message page on success if no error in password reset
- Is there a hook for updated image metadata upon using image editor?
- how to execute a function only when i send an order to trash [closed]