remove_filter( ‘the_content’, ‘wpautop’ ); only for certain post types

Hook into the_content before the wpautop filter has been called, check the post type, and remove the wpautop filter, which is added in wp-includes/default-filters.php with the default priority 10: add_filter( ‘the_content’, ‘wpse_82860_remove_autop_for_posttype’, 0 ); function wpse_82860_remove_autop_for_posttype( $content ) { # edit the post type here ‘post’ === get_post_type() && remove_filter( ‘the_content’, ‘wpautop’ ); return $content; … Read more

Clarification on filters and hooks

I am confused because add_filter uses the word add when I feel like it is more on the lines of replace or overwrite (unless I am misunderstanding) You are misunderstanding. Both add_action and add_filter insert function callbacks into a kind of queue. You can add many callbacks to the same hook and they will fire … Read more

Filter username field on registration for profanity and unwanted words

There are two very different hooks you can use, depending on the installation: wpmu_validate_user_signup for multi-site and registration_errors for single-site. The following untested code shows how to use them. You can tweak the array in user_name_is_forbidden() to your needs. Use regular expressions for the matches. // multi-site add_filter( ‘wpmu_validate_user_signup’, function( $result ) { // there … Read more

Filter translations (gettext strings) on specific admin pages

According with the codex, get_current_screen() has to be used later than admin_init hook. After a few tests, it seems that the safiest way is to use current_screen action hook instead of get_current_screen(): add_action(‘current_screen’, ‘current_screen_callback’); function current_screen_callback($screen) { if( is_object($screen) && $screen->post_type == ‘mycpt’ ) { add_filter( ‘gettext’, ‘theme_change_comments_label’, 99, 3 ); } } function theme_change_comments_label( … Read more

What does (10, 2) mean when used with add_filter

Have a look at the codex page for add_filter. The 10 is the $priority parameter (10 is default) which defines when your function will run in regards to the other functions which are attached to the nav_menu_css_class filter. 2 is the $accepted_args parameter which tells wordpress how many parameters the function you want to add … Read more

Where to hook into post content?

You can use the_content with an high prioriety (lower number). add_filter( ‘the_content’, function( $content ) { return ‘Hello World ‘.$content; }, 0); You can even use negative priority: add_filter( ‘the_content’, function( $content ) { return ‘Hello World ‘.$content; }, -10); Note that this will apply everytime ‘the_content’ is used, no matter the post type, or … Read more

Remove Editor From Homepage

There are a couple of issues with your approach By using the admin_init hook you won’t have any reference to the post object. This means you won’t be able to get the post ID or use anything like get_the_ID because the post won’t actually be loaded. You can see that in the order here https://codex.wordpress.org/Plugin_API/Action_Reference … Read more

How to pass/get data to/from the WooCommerce data-product_variations object?

jQuery(document).on(‘found_variation.wc-variation-form’, ‘form.variations_form’, function(event, variation_data) { //this is called when a valid productis found }); jQuery(document).on(‘change.wc-variation-form’, ‘form.variations_form’, function(event) { //this function is called when the user clicks or changes the dropdown }); The PHP function you are looking for is apply_filters( ‘woocommerce_available_variation’, array( ‘attributes’ => $variation->get_variation_attributes(), ‘availability_html’ => wc_get_stock_html( $variation ), ‘backorders_allowed’ => $variation->backorders_allowed(), ‘dimensions’ => … Read more