Articles of filters

What's the difference between hooks, filters and actions?

This question already has an answer here: Difference Between Filter and Action Hooks? 3 answers

Make a function to run only for CPTs

I found an answer where the author comments in the code that the post_type_link filter is (only?) for CPTs. How he/she can be sure that his code will run only for CPTs? From the WordPress Codex: post_type_link is a filter applied to the permalink URL for a post OR custom post type prior to being […]

Dynamically Override Fancy Title

I’m trying to override Fancy Title created using The7 Theme. The7 Titles are generate from this function: function presscore_get_page_title() { $title = ”; if ( is_page() || is_single() ) { $title = get_the_title(); } else if ( is_search() ) { $title = sprintf( __( ‘Search Results for: %s’, ‘the7mk2’ ), ‘<span>’ . get_search_query() . ‘</span>’ […]

How does WordPress call functions attached to a certain action hook before calling functions attached to other hooks

We know that there is a certain order for the execution of callback functions attached to action hooks. How does WordPress decide which action should be prioritized while executing all the hooks?

Same Conditionals Not Working on Two Different Hooks

Everyone! I am new to WP and trying to build a plugin. I have the following codes working properly: add_filter(‘the_content’, ‘say_hello’); function say_hello($content){ if(is_single() || is_page()){ print $content.” Thank you for reading!”; } else { print $content; } } But the following codes don’t seem to work: add_action(‘init’, ‘prepare_head’); function prepare_head(){ if(is_single() || is_page()){ // […]

Using 'posts_where' on a query with a custom field

I have a page which displays tour dates for an artist. I use a custom field (TheDate) to give each entry a numerical value so that they will show up in the proper order (regardless of when they were actually posted). The custom field uses these values: 20110315 (this would be used for a date […]

Return a custom value in a function added to an action hook

I looked into the difference between action and filter hooks, and as far as I understand, it is not possible to have a function, which is added to an action hook, return a (custom) value. My scenario: Upon saving a post, I try to save another post. Therefore I use add_action( ‘save_post’, ‘create_another_post’); Depending on […]

How can filters be run when they are never applied?

I’m trying to track down why menu switching by language in the polylang filter is not working correctly. I’m looking at the function nav_menu_locations which is added as a filter as such: add_filter(‘theme_mod_nav_menu_locations’, array($this, ‘nav_menu_locations’), 20); and then defined subsequently as: public function nav_menu_locations($menus) { … return $menus; } I inserted statements to echo $menus […]

Please explain me what the do_action does

I am trying hard to understand do_action but not understanding. I was studying the blane theme. And they have this code in sidebar.php <div id=”secondary” class=”widget-area col-md-3″ role=”complementary”> <?php do_action( ‘before_sidebar’ ); ?> <?php if ( ! dynamic_sidebar( ‘sidebar-1’ ) ) : ?> <aside id=”search” class=”widget widget_search”> <?php get_search_form(); ?> </aside> <aside id=”archives” class=”widget”> <h1 […]

Filters post in admin with dropdown select, custom post type

I’m trying to filter my post in my admin area with a custom filter dropdown. I use this method to make it: Here is my code: add_action( ‘restrict_manage_posts’, ‘wpse45436_admin_posts_filter_restrict_manage_posts’ ); function wpse45436_admin_posts_filter_restrict_manage_posts(){ $type = ‘post’; if (isset($_GET[‘post_type’])) { $type = $_GET[‘post_type’]; } //only add filter to post type you want if (‘post’ == $type){ […]