How to remove Text area of comment in Wordpress? - php

Hellow there all I tried searching everywhere but I coudn't just find it - may be because its a wiered requirement all I want to do is remove my Comment Text area in wordpress comment - I sucessfully removed URL website and name in the comment field by using following code
<?php
function remove_comment_fields($fields) {
unset($fields['url']);
unset($fields['author']);
unset($fields['email']);
return $fields;
}
add_filter('comment_form_default_fields','remove_comment_fields');
?>
But not able to remove the Text area - Actually you all will thought what will I do removing all this I am using a plugin which allow you to post images in your comment and the only option I want to give to user is post images via comment. please guide me.

Two options, the comment_form_defaults filter:
add_filter( 'comment_form_defaults', 'so16856397_comment_form_defaults', 10, 1 );
function so16856397_comment_form_defaults( $defaults )
{
$defaults['comment_field'] = '';
return $defaults;
}
or the comment_form_field_comment filter:
add_filter( 'comment_form_field_comment', 'so16856397_comment_form_field_comment', 10, 1 );
function so16856397_comment_form_field_comment( $field )
{
return '';
}
Check the comment_form source code.

You can also hide the textarea comment box by taking its id set to display:none from CSS

Just simple, add this code in functions.php file
function disable_comments_everywhere( $open, $post_id ) {
return false;
}
add_filter( 'comments_open', 'disable_comments_everywhere', 10 , 2 );

Related

Hide ACF Metabox on page edit but show on post edit

I have a bit of a unique issue that I've been struggling with all weekend and hopefully someone can help shed some light here.. I have several ACF groups that I've specified to show on both posts and pages edit page. Although I am storing values (programmatically) in the ACF fields on pages, I need to hide that group on the pages edit screen but still show it in the post edit screen.
The following code works until I try to find a condition that identifies if user is on the page edit screen rather than the post edit screen
function my_remove_meta_boxes() {
if ( get_post_type() == 'page' )
{
$out = '';
$out .= '<style>#acf-group_61699b806807f {display: none !important;} </style>';
echo $out;
}
}
add_action( 'admin_menu' , 'my_remove_meta_boxes' );
if tried get_current_screen, is_page, and get_post_type but nothing seems to work. Any help would be huge. Thanks!
You'll have to use get_current_screen() function it will give you screen object and you'll match the screen id in if statment.
you also need to use admin_head to write your custom css with style tag.
The code will be like this:
function vh_acf_remove_meta_boxes() {
$screen = get_current_screen();
$screen_id = $screen->id ? $screen->id : '';
if ( 'page' === $screen_id ) {
echo '<style>#acf-group_61699b806807f {display: none !important;}</style>';
}
}
add_action( 'admin_head', 'vh_acf_remove_meta_boxes' );

Unset some WooCommerce checkout billing fields and One Page Checkout plugin

I am using WooCommerce Subscription and One Page Checkout plugins.
I am able to unset billing first name and last name (and even set 'required' attribute to false, so both fields are successively removed from my One page checkout.
But when I fill all other fields and I place order, it displays a validation error notice: "Billing First Name and Last Name are required" and I am not really sure how to solve this problem?
Maybe it has been set again from some functions or so? How I can solve this?
To remove billing first name and last name without any issues in checkout page, try to use the following instead:
// 1. Make required fields optional
add_filter( 'woocommerce_default_address_fields', 'customize_default_address_checkout_fields', 1000 );
function customize_default_address_checkout_fields( $fields ) {
if( is_checkout() ) {
$fields['first_name']['required'] = $fields['last_name']['required'] = false;
}
return $fields;
}
// 2. Remove unneeded billing fields
add_filter( 'woocommerce_billing_fields', 'customize_billing_checkout_fields', 1000 );
function customize_billing_checkout_fields( $fields ) {
if( is_checkout() ) {
unset($fields['billing_first_name'], $fields['billing_last_name']);
}
return $fields;
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works…
It should works with One Page Checkout plugin too.
Have you tried removing it manually via child function.php as below?
add_filter( 'woocommerce_checkout_fields' , ' custom_remove_checkout_fields ' );
function custom_remove_checkout_fields( $fields ) {
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
return $fields;
}
I have solved the issue already.
The root cause is because one plugin always required Billing First Name and Last Name so I use this tip below to passby the problem:
I included this code into function.php of the theme:
add_filter('woocommerce_billing_fields', 'my_woocommerce_billing_fields');
function my_woocommerce_billing_fields($fields) {
$fields['billing_first_name']['default'] = 'newSubscriber';
$fields['billing_first_name']['custom_attributes']['readonly'] = TRUE;
$fields['billing_last_name']['default'] = 'newSubscriber';
$fields['billing_last_name']['custom_attributes']['readonly'] = TRUE;
return $fields;
}
So now your first name and your last name is always set as 'newSubscriber', it will pass the validation and now you hide it from dislaying using css:
p#billing_first_name_field, p#billing_last_name_field {
display: none;
}
paste these css into appearance -> Theme-> yourtheme-> additional css and save it.
So now everything would work as charm.
Hope it would help somebody struggling with the problem.

WooCommerce - Add content on the thank you page by the shipping method

I would like to place my own content (in my case a shortcode) on the thank you page at WooCommerce after completing the order, which depends on the shipping method.
So for example:
Shipping Method 1: Content 1
Shipping Method 2: Content 2
Shipping Method 3: No content
I have already found something for text here, but i dont get the shortcode inserted. Alternatively I have tested what works with the shortcode here, where the dependency on the shipping method is missing.
Maybe someone can help me to implement this.
Ideally the content should be above the table with the order information.
Thanks a lot!
May be the way you added the shortcode to the thank you text can be the issue.
See the following shortcode function called avengers which i created for demo.
function call_avangers( $atts ){
return "<p>Avengers . . . . Assemble !!!</p>";
}
add_shortcode( 'avengers', 'call_avangers' );
You can display this shortcode in thank you page using the below function
add_filter( 'woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $text, $order ) {
if( $order->get_shipping_method() == 'your_shipping_method_here' ) {
$text .= do_shortcode('[avengers]');
}
return $text;
}
The basic thing is you have to call do_shortcode('your_shortcode_name')

Remove page title on the attachment page

I am really quite new to programming and I need help with something that I think is not difficult. What I want is to delete the title of the attachment page, I have searched and in this forum I have found a code that has worked partially. That is, the code removes the title but also removes the menu from the attachment page. I have searched everywhere, and I have seen that conditional tags are required to generate that function, however, I am a beginner in the world of websites and I need your help. The code is the following:
add_filter( 'the_title', 'remove_page_title', 10, 2 );
function remove_page_title( $title, $id ) {
if (is_attachment())
return '';
return $title;
}
Thanks in advance for your help.
In your child theme you would add this into the functions.php file:
function remove_page_title( $title, $id ) {
if (is_attachment()):
return '';
return $title;
endif;
}
remove_action('virtue_page_title_container', 'remove_page_title', 20);
I hope it would help you out.

how to disable the comments for specific category in wordpress?

How can i disable the comments form for a specific category in Wordpress.
And i mean with that every post the user will publish it in this category will not has a comment form content.
Rather than doing this in functions.php, you could create two template files. The first template file is your standard theme template, the second would be identical, except it wouldn't contain the comment code section.
Simply name the template file that doesn't have the comment code block category_{id}.php and upload to your theme folder. The ID is the ID of the category you want to disable comments on.
More information on category specific templates here https://developer.wordpress.org/themes/basics/template-hierarchy/#category
More information about the comment template here https://codex.wordpress.org/Function_Reference/comments_template
If you still want to do this via functions.php, see this blog post http://spicemailer.com/wordpress/disable-hide-comments-posts-specific-categories/ which uses the following code snippet
add_action( 'the_post', 'st_check_for_closed' );
function st_check_for_closed()
{
global $post;
$my_post_cat = wp_get_post_categories($post->ID);
$disabled_cat = array( "1", "3"); // this is he array of disabled categories. Feel free to edit this line as per your needs.
$my_result = array_intersect($my_post_cat,$disabled_cat);
if (empty ( $my_result ) )
{
return;
}
else {
add_filter( 'comments_open', 'st_close_comments_on_category', 10, 2 );
add_action('wp_enqueue_scripts', 'st_deregister_reply_js');
}
}
function st_deregister_reply_js()
{
wp_deregister_script( 'comment-reply' );
}
function st_close_comments_on_category ($open, $post_id)
{
$open = false;
}

Categories