Add filter to get_posts
Why not use the include (or conversely, exclude) argument for get_posts()? It takes an array of post IDs.
Why not use the include (or conversely, exclude) argument for get_posts()? It takes an array of post IDs.
While your answer is very interesting and I like it, I still want to post another proposal, just let you have another choice 🙂 IMHO, if the data contains only simple fields, like: array( ‘name’ => ‘my name’, ‘address’ => ‘my address’, ‘phone’ => ‘01234’, ); then you can use the code below: add_filter( ‘wpse63692_example_filter’, … Read more
Just filter ‘the_content’, test if you are on the correct page, then run str_ireplace(): add_filter( ‘the_content’, ‘wpse_76808_filter_h1’ ); function wpse_76808_filter_h1( $content ) { // page slug if ( ! is_page( ‘privacy-policy’ ) ) return $content; return str_ireplace( ‘<h1’, ‘<a href=”#”>Back to the top</a><h1’, $content ); }
Filters and Actions are similar under the hood, but with an important difference- Actions allow you to do something when an event occurs- WordPress does something and executes an action to let you do your own thing. A function hooked to an action may or may not produce output, but it never returns a value … Read more
Unfortunately, this isn’t quite as easy as you might expect, nor is it properly achievable by using filters. WordPress offers very little hooks for widgets in general, let alone for widget content. However, as all widgets are generated by classes, you can extend the functionality WordPress offers by creating your own widget, extending the recent … Read more
Two problems here: #1 You’re missing the $accepted_args argument in: add_filter( $tag, $callback_function, $priority, $accepted_args ); Check out the Codex here for more info on that. #2 Note that $link . “?program_year=2016” is problematic, since it gives us this kind of link: /?p=123&preview=true?program_year=2016 But using instead add_query_arg( [ ‘program_year’ => ‘2016’ ], $link ) we … Read more
I’ve been looking for a filter for category_description() and I have not found any. You could use wp_trim_words() with category_description() to get the desired result. For example: $cat_ID = 4; // wp_trim_words( $text, $num_words = 55, $more = null ); echo wp_trim_words( category_description( $cat_ID ), 55, ‘<a href=”‘ . get_category_link( $cat_ID ) . ‘”>’ . … Read more
Any comments_template filter should return an absolute filepath to the comments template – use comment_form_defaults and set the class_form argument: add_filter( ‘comment_form_defaults’, function ( $args ) { $args[‘class_form’] = ‘my form classes’; return $args; });
Problem The issue is that WordPress uses call_user_func() or call_user_func_array() to allow plugin/theme developers to add callables to hooks. Callables, or callback functions, can be simple functions, object methods, or static class methods. We need to format the callable as either a string or array depending on the type of callback we want. Simple Functions … Read more
You can use the wp_add_inline_style() function to override styles in an already-enqueued stylesheet: add_action( ‘admin_enqueue_scripts’, ‘wpse127850_css_overrides’ ); function wpse127850_css_overrides() { wp_add_inline_style( ‘color’, ‘.mycolor { background: #ccc; }’ ); } You’ll need to find the handle of the stylesheet you want to affect — I’ve guessed at color but there’s no guarantee I’m right. References wp_add_inline_style() … Read more