Tag Info

Hot answers tagged

5

The problem is that filters in WordPress are global; if you add a filter somewhere it persists everywhere, unless you remove it. Also consider that you should prefer composition over inheritance, and if your current application structure is already built upon inheritance, and you can't or don't want to change it, you should avoid at least using filters for ...


3

If you hook some functions to the before_sidebar action, they will be executed in your code. Your action is now probably without any function hooked, so it returns nothing. Example: <?php add_action( 'before_sidebar', function() { echo 'Try me!'; }); add_action( 'before_sidebar', function() { echo 'Yep. '; }, 1); // this should output "Yep. Try ...


3

Your problem isn't that you did the wrong thing, it's that you did it at the wrong time. When it happens is important, not where. In a child theme, the functions.php is loaded, then the parents, so you're doing this: Remove the first_paragraph function from the_content filter Add the first_paragraph function to the_content filter Clearly this is the ...


2

To change the mode URL variable but in the load try this: add_action( 'load-edit.php', 'my_default_posts_list_mode' ); function my_default_posts_list_mode() { $post_type = isset( $_GET['post_type'] ) ? $_GET['post_type'] : ''; if ( $post_type && $post_type == 'my_post_type' && !isset( $_REQUEST['mode'] ) ) $_REQUEST['mode'] ...


2

After checking out the code, the best way to do this would be to use the wp_editor_settings filter in /wp-includes/class-wp-editor.php. When you call wp_editor() it internally makes a call to _WP_Editors::editor($content, $editor_id, $settings);. This function first passes the $settings array through parse_settings() which uses that filter. add_filter( ...


1

The problem lies in the attachment-filter= URL parameter. The slash between application/pdf (or else) is being escaped twice. When you replace the %252F with a slash or %2F the filter will work. The first escaping (/ becomes %2F) happens when WP is building the selectbox containing the mime types. The second one (%2F becomes %252F) is performed by the ...


1

The accepted arguments value is used by WordPress as $length argument for array_slice when performing the action. It means that, yes, if you pass 0 no argument will be passed to your callback. However, you should care of that only if your function acts differently if an argument is passed or not. A function like the one in OP, is defined without any ...


1

Can you try adding the following code to the functions.php file in your theme directory and see if works for you function keep_raw_filename( $filename, $filename_raw ) { return $filename_raw; } add_filter( 'sanitize_file_name', 'keep_raw_filename', 10, 2 );


1

You need to return the filtered content, try like this: add_filter('the_content', 'emd_content'); function emd_content( $content ) { if ( is_page('Member Directory') ) { include dirname( __FILE__ ) . '/content-members.php'; } elseif ( is_page('Contact Members') ) { include dirname( __FILE__ ) . '/content-member-contact-form.php'; ...


1

I've been struggling with the same problem...when args[0] is publish, args[2] is not populated. You have to get it from the url. if(substr($args[0],0,7)=="publish"){ $postid=$_GET["post"]; if(!isset($postid))return $allcaps; } else $postid=$args[2];


1

Ashok's answer works, but I also found the following, which is what I decided to go with. In a nutshell, a filter must always return a value - the_content() just echos and is likely causing an infinite loop since it would call your filter. function emd_content($content) { if ( is_page('Member Directory') ) { $content = include dirname( ...


1

I think that you can improve performance saving view information in one single option instead in post meta applying the filter date on saving instead of on retrieving create the markup and save in a transient instead of saving the query (fragment caching) Rough implementation in a class class PopularPosts { const OPT = 'myplugin_popular_posts'; ...


1

If you are using WordPress 4.0+ you can do this using the wp_editor_settings and the global $pagenow to determine if you are on the comments page. add_filter( 'wp_editor_settings', 'remove_editor_quicktags', 10, 2 ); function remove_editor_quicktags( $settings, $id ){ global $pagenow; if ( $id == 'content' && $pagenow === 'comment.php' ){ ...



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