Tag Info

New answers tagged

1

Please refer below : function disable_new_posts() { // Hide sidebar link global $submenu; unset($submenu['edit.php?post_type=CUSTOM_POST_TYPE'][10]); // Hide link on listing page if (isset($_GET['post_type']) && $_GET['post_type'] == 'CUSTOM_POST_TYPE') { echo '<style type="text/css"> #favorite-actions, .add-new-h2, .tablenav { ...


0

Just to add to Pippin's answer, in my case some content were also being shown in other parts of the single page, e.g. sidebar. Checking just is_single() also triggered the content modification in the other areas. Here's another check so that only the main content will have appended stuff: function yourprefix_add_to_content( $content ) { if( is_single() ...


0

You can modify the query using the pre_get_posts hook, you will have to add the parameters of your query to the query provided by WordPress inside you callback function (exclude_category in the example below): Example from the WordPress Codex: function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { ...


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' ){ ...


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'; ...


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 ...


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 ...


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( ...


0

'apply_filters' runs the value through all of the other hooks / functions attached to it. Try an experiment: print_r( $type ); print_r( apply_filters("{$type}_upload_directory", $type) ); While you might, in your case, get the same thing - the apply_filters makes sure that any other plugins that try to influence this upload directory will still work.


0

I accomplished this by first hooking into the 'current_screen' action and making a determination if my post_type was set, then adding the filter. There may be a shorter way but this works if you need to change the text only on a given post type. public function set_featured_image_filter(){ $screen = get_current_screen(); if( ...


0

You'll need a loop before you get to your sidebar loop to initiate your unique values. You could run the same loop twice, with rewind_posts() between the two loops ( so you get your original loop, starting from index 0 ). In your first loop, loop through and add all your values to an array so that the array looks something like this: Array( [0] => ...


0

I've tried and succeeded. But when I click one of the categories, the page returned to the Top (Srcoll above). But conten appears. It's just back to the top of the page. Not in place. Where is my mistake? Thank you.


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 ...


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'] ...


0

Yea, you can. You need to define the scope of callback function, if that doesn't make sense, don't worry, it's the sort of thing you pick up as you write code more and more. Essentially, you need to tell the filter, which is using the php function call_user_func_array() internally, where to find the function you want to call. Functions defined outside of ...


0

I got it. public function auth($user, $username='') { if ( !empty($username) ) { return new WP_Error( 'broke', __( "custom error" ) ); } else return $user; } It only returns error if username is submitted. A good base for my plugin. But I didn't know how to set priority so thank you for that.


0

The filter runs on every page load, but the first argument will be a WP_User object only on successful submission. It will be null if nothing was submitted, but most likely it will be a WP_Error object, which you can check for. If you want to know the specific error you have to look at the errors the object contains. The case where the form was not submitted ...


0

Yes set priority to something like 999 or something really high. The default priority is 10, and you currently have yours at 1 and therefore will occur first. The priority is explained in the codex: http://codex.wordpress.org/Function_Reference/add_filter notably: $priority (integer) (optional) Used to specify the order in which the functions ...


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 ...


0

function property_slideshow( $content ) { if ( is_singular( 'property' ) ) { $custom_content = do_shortcode( '[portfolio_slideshow]' ); $custom_content .= $content; } return $custom_content; } add_filter( 'the_content', 'property_slideshow' ); The is_singular conditional tag checks if a singular post is being displayed ...


0

You can also use this add_filter( 'wp_nav_menu_items','add_search_box', 10, 2 ); function add_search_box( $items, $args ) { $items .= '<li>' . get_search_form( false ) . '</li>'; return $items; }


0

class MyPluginClass { public function __construct() { add_action( 'save_post', array( $this, 'myplugin_save_posts' ) ); } public function myplugin_save_posts() { // do stuff here... } } $mypluginclass = new MyPluginClass(); check in Using Add Action In Your Class in WordPress Codex


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


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 ...


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'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

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'; ...



Top 50 recent answers are included