Filter the_content to add something before each element?

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 ); }

Wrapping my head around add_filter

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

Add Bootstrap Classes to Recent Posts Widget

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

preview_post_link for Custom Post Types

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

How to customize category_description()?

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

Adding a filter to comments_template

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; });

Filter Hook callback error, is it due to using $this inside a filter or something else?

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

WP filter to alter admin CSS styles?

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

How to get a single hook from wp_head()?

wp_head is an essential part of the theme, and there is too many things that might fall apart if it is not there. Hunting and fixing them one by one might be time consuming and the worthiness of the all operation questionable. In you snippet for example you want to remove things that make no … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)