Archives: <span>Code Snippets</span>

upload media from url

<?php $image_url ='https://www.freelancedev.in/wp-content/uploads/2021/04/upload.png'; $imagextension = end(explode('.',$image_url)) ; $image_name = 'imagename.'.$imagextension; $upload_dir = wp_upload_dir(); $image_data = file_get_contents($image_url); // Get image data $unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name $filename = basename( $unique_file_name ); // Create image file name // Check folder permission and define file location if( wp_mkdir_p( $upload_dir['path'] ) ) { $file […]

Condition Based on Single page for targeting specific post type

<?php // condition for targeting single by ID , Title if (is_single('17')){ //target single page of id **17** } if (is_single('demo')){ //target single page title **demo** } //This Condition will execute on Single **Post** Page only if ( is_single() && 'post' == get_post_type() ) { } //This Condition will execute on Single of custom post […]

Condition for Check Single Page

<?php if( is_front_page() && is_home() ) { // This condition will run on if no homepage is selected }elseif( is_front_page() ) { // This condition will run on static homepage is any page is selected as home } elseif ( is_home() ) { // This condition will run only on blog page } ?>

Woocommerece Add To Cart Button Text on Single Product Page

add_filter( 'add_to_cart_text', 'freelancedev_custom_single_add_to_cart_text' ); add_filter( 'woocommerce_product_single_add_to_cart_text', 'freelancedev_custom_single_add_to_cart_text' ); function freelancedev_custom_single_add_to_cart_text() { return __( 'Buy Now', 'woocommerce' ); }

WooCommerce Button Text on Archive page.

add_filter( 'add_to_cart_text', 'freelancedev_custom_product_add_to_cart_text' ); // < 2.1 add_filter( 'woocommerce_product_add_to_cart_text', 'freelancedev_custom_product_add_to_cart_text' ); // 2.1 + function freelancedev_custom_product_add_to_cart_text() { return __( 'Buy Now', 'woocommerce' ); }

Radio Button Style

.wpcf7-radio input[type="radio"]{display:none} .wpcf7-radio .wpcf7-list-item-label::before { content: ''; position: absolute; left: 0; top: 0; width: 18px; height: 18px; border: 1px solid #ddd; border-radius: 100%; background: #fff; margin: auto; bottom: 0; } .wpcf7-radio input[type="radio"] { display: none; } .wpcf7-radio .wpcf7-list-item-label { padding-left: 30px; line-height: 30px; display: block; position: relative; } .wpcf7-radio .wpcf7-list-item-label::after { content: ''; width: 12px; […]

Styling of radio button and checkbox

.wpcf7-checkbox .wpcf7-list-item-label::before { content: ''; position: absolute; left: 0; top: 0; width: 18px; height: 18px; border: 1px solid #ddd; border-radius: 100%; background: #fff; margin: auto; bottom: 0; } .wpcf7-checkbox input[type="checkbox"] { display: none; } .wpcf7-checkbox .wpcf7-list-item-label { padding-left: 30px; line-height: 30px; display: block; position: relative; } .wpcf7-checkbox .wpcf7-list-item-label::after { content: ''; width: 12px; height: 12px; […]

Radio and Checbox

[checkbox checkbox-193 use_label_element "Option 1" "Option 2" "Option 3" "Option 4"] [radio radio-67 use_label_element default:1 "Radio 1" "Radio 2" "Radio 3" "Radio 4"]

Default Form Css

/*Styling Label of form */ .wpcf7-form label { width: 100%; float: left; margin-bottom: 15px; font-weight: bold; text-transform: uppercase; } /*Styling form Input Field, Textarea */ .wpcf7-form label .wpcf7-form-control { float: left; margin-top: 10px; background-color: #fff; border: 2px solid #e5e5e5; color: #a7a7c1; padding: 8px 28px; line-height: normal; font-size: 14px; min-height: 50px; /*This will use for input […]