Tag Info

Hot answers tagged

4

I am doing something like this in one of my plugins: function my_body_class( $c ) { global $post; if( isset($post->post_content) && has_shortcode( $post->post_content, 'your-shortcode' ) ) { $c[] = 'your-class'; } return $c; } add_filter( 'body_class', 'my_body_class' ); I'm not sure it was really necessary, but I ...


3

The strings was new, not more for your requirements. This is the new content of the hook. array ( 'selector' => '#content', 'resize' => 'vertical', 'menubar' => false, 'wpautop' => true, 'indent' => false, 'toolbar1' => ...


3

Use a use statement: add_filter( 'single_template', function ( $template ) use ( $name ) { Or just pass all templates at once, and create just one function: add_filter( 'single_template', function ( $file ) use ( $templates ) { global $post; if ( in_array ( $post->post_type, $templates ) ) return __DIR__ . ...


3

'the_posts' is an action fired everytime WP_Query get posts, for main query and for other secondary queries, so when you do something like: $foo = new WP_Query($args); in a widget or elsewhere (shortcode, related posts...) 'the_posts' is triggered again. However there is only one main query, so you can use a conditional and do what you do only if the ...


3

wp_terms_checklist early trigger a filter 'wp_terms_checklist_args' so you can use that filter to add your filter and auto-remove it haver 1st run. This should be enough, however, once hooks are global variables, to be sure is better use some stronger check, a static variable inside a function is a simple and nice trick: function switch_terms_filter( $_set ...


2

What Adam Brown's site says is that the hook no longer appears in 3.8. I greped a 3.9 and found: bash-4.2# grep -Rni 'content_save_pre' * wp-includes/kses.php:1327: * The wp_filter_post_kses() function is added to the 'content_save_pre', wp-includes/kses.php:1344: add_filter('content_save_pre', 'wp_filter_post_kses'); wp-includes/kses.php:1370: ...


2

I copied your code to a file in my home directory on my Ubuntu box, removed the weird character that @s_ha_dum noticed, and ran it. It worked as I'd expect. Code: <?php function get_the_post_imgs($oldPostContent) { $newPostContent = $oldPostContent; $newPostContent = preg_replace_callback( "/<img.*src=[\"']([^\"']*)[\"'].*>/i", ...


2

Your code doesn't really do any "user logged in" check, and you aren't using a couple of the globals you import. function restrict_access_to_unlogged_users($template) { if (!is_user_logged_in()) { $template = get_stylesheet_directory() . '/need-login.php'; } return $template; } add_filter( 'page_template', 'restrict_access_to_unlogged_users', 20 ...


2

You are using wrong number of arguments in add_filter, you specified to get 2 arguments and you are looking for third one: Update your add_filter code to this: add_filter( 'manage_post_tag_custom_column' , 'my_custom_column' , 10 , 3 ); The 3 in the end tells the filter to provide all the three arguments to your function.


2

These fields are created in Walker_Nav_Menu_Edit::start_el(). To change or to remove them, create a custom walker (example for another walker) that extends Walker_Nav_Menu_Edit and uses other or less fields. Then filter wp_edit_nav_menu_walker and return the class name of your walker. Pseudo-code: class Walker_Nav_Menu_Edit_Simple extends ...


1

The problem is that you can't distinguish form an anonymous function and another, so yes, it is possible to remove a closure (i.e. anonymous function) but if more than one closure act on same filter at same priority you have to make a choice, remove them all, ore remove only one (without knowing exactly which). I'll show how to remove them all using a ...


1

add_filter('some_base_handle'.sanitize_title($string), ...) What he's doing here is a variable filter handle, and while "sanitize_title" might not be exactly the correct function to use here, it really depends on what the possible values of $string are and what the source of that $string is. Variable filter names can be handy if you have a lot of different ...


1

Remove your filter and add orderby'=>'post__in'. That sort order in not automatic when you supply IDs. $wp_query = new WP_Query( array( 'post__in' => $arrayPostsIds, 'ignore_sticky_posts' => true, 'date_query' => $date_query , 'orderby' => 'post__in', ) );


1

wp_nav_menu_items aren't mentioned in the codex, so there are no concrete description on how to use it. wp_nav_menu_items can be found on line 347 in wp-includes/nav-menu-template.php $items = apply_filters( 'wp_nav_menu_items', $items, $args ); within wp_nav_menu. In the codex, it states the following Displays a navigation menu created in ...


1

For posts is set up by loop (see setup_postdata()) it is split into parts and array of those parts is assigned to global $pages variable. Even if it's not paginated this is still where data goes. Then that variable is actually where get_the_content() looks for post content to process and output, not actual post object. In your function you are overriding ...


1

Even if is not very flexible filter you can use the gettex hook. Only be aware that this filter runs for every string being translated, so can affect performarce if over-used. To narrow the performance impact you can add it only of admin footer, and remove it just after had use it: add_action('admin_footer', function() { add_filter( 'gettext', ...


1

Per the Codex: relation (string) - The logical relationship between each inner taxonomy array when there is more than one. Possible values are 'AND', 'OR'. Do not use with a single inner taxonomy array. So you are on the right track, but your tax_query is wrong. relation is part of the outer tax_query array and not part of the top level query ...



Only top voted, non community-wiki answers of a minimum length are eligible