Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

Thursday, 10 December 2020

Create A Folder If It Doesn't Already Exist In WordPress Or PHP


 <?php 

if (!file_exists('home/public_html/example.com/wp-content/uploads/blog')) {

    mkdir('home/public_html/example.com/wp-content/uploads/blog', 0777, true);

}

?>


According To Question:

#mkdir php

#check if directory exists php

#how to create directory dynamically in php

#create directory in php file upload

#create folder inside folder in php

#php mkdir not working

#php mkdir 777

#php mkdir()

Friday, 23 October 2020

WordPress Post Views Count Without Plugin

 Step1"
Add this code in current WordPress active theme in function.php file

<?php

function get_PostViews($postID){
    $count_key = 'post_views_count';
    $post_count = get_post_meta($postID, $count_key, true);
    if($post_count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 View";
    }
    return $post_count.' Views';
}

function set_PostViews($postID) {
    $count_key = 'post_views_count';
    $post_count = get_post_meta($postID, $count_key, true);
    if($post_count==''){
        $post_count = 0;
       delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $post_count++;
        update_post_meta($postID, $count_key, $post_count);
    }
}
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
?>

 Step2:
Now add this function code in active themes in single.php file within the loop. It will manage the views and set the post views of each post.

<?php
 set_PostViews(get_the_ID());
?>

 Step3:
Add this code line in inside the post loop where you want to display post count.

<?php
 echo get_PostViews(get_the_ID());
 ?>


Saturday, 12 September 2020

How to Custom Pagination For Custom Post in WordPress?

 

There are very simple steps for Pagination for any type of Post in WordPress by Shortcode with Ajax.

  1.  Write this below code in you active WordPress theme's funcntion.php file.
    • ie: \wp-content\themes\twentytwenty\functions.php
  2.  Put this shortcode in your page where you want to display WordPress Custome Post or Post with Ajax Pagination.
    • <?php echo do_shortcode('[php_kishan_wp_portfolio_post_list per_page="30" total="90" post_type="post"]'); ?> OR
    • [php_kishan_wp_portfolio_post_list per_page="30" total="90" post_type="post"]
### Code: ###
<?php
function function_php_kishan_wp_portfolio_post_list($atts, $content = null) {
    ob_start();
    $atts = shortcode_atts(
    array(
        'per_page' => '',
        'total' => '',
        'post_type' => '',
    ), $atts);
    $per_page = $atts['per_page'] ? $atts['per_page'] : '9';
    $total_post = $atts['total'] ? $atts['total'] : '-1';
    $post_type = $atts['post_type'] ? $atts['post_type'] : 'post';

    global $wpdb;
    $post_type = $post_type; // define your custom post type slug here
    // A sql query to return all post titles
    $results = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE post_type = '$post_type'  and post_status = 'publish' order by post_title ASC limit 0,$per_page");
.
.
.
.
return ob_get_clean();
}
add_shortcode('php_kishan_wp_portfolio_post_list', 'function_php_kishan_wp_portfolio_post_list');
#### [php_kishan_wp_portfolio_post_list per_page="30" total="90" post_type="post"] ####

Click here for download full code.

Saturday, 29 August 2020

How To Fix Email Spam Issue In Contact Form 7?

 Some times Contact Form 7 gives 

Error: An error occurred while trying to send your message. Please try again later.

on form submit.

That time you need to add this belove filter in functions.php which themes is active in your WordPress site.

       add_filter('wpcf7_spam', '__return_false');




Wednesday, 5 August 2020

How To Create A Navigation Menu In WordPress?

There are very simple steps to Create A Navigation Menu in WordPress.

1. You need to go in the Appearance » Menus page in your WordPress admin dashboard. 2. You can choose the pages you want to add to the menu. 3. Menu Settings » Select Display location. 4. Save menu. 5. You can see on your WordPress Website after refreshing any page. 

You can see Create A Navigation Menu tutorial on the below Video.


Thursday, 11 June 2020

I want to remove shortcode from content [vc_row][vc_column][vc_column_text]

$content = get_the_content(); 
$content = preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', $content);
$content = wp_strip_all_tags($content);
echo $content; 

### OR ###

$content = get_the_content(); 
$content = do_shortcode($content);
echo $content;

Monday, 1 June 2020

How To Disable Automatic Updates in WordPress by Custom Plugin?


Using a simple plugin.

Did you know about automatic updates on the WordPress website?

Some time Some Core, Plugins, and Themes are auto-update in your live WordPress site.
That time you lose some custom changes and some other setting in your site.

How to prevent this type of loss and stop auto-update?
Let's follow these simple 4 steps:
1. Download the simple plugin WP Disable Automatic Updates
2. Upload in your WordPress site.
a. Go to in your Wordpress backend wp-admin menu > Plugins > Installed Plugins
b. Click on Plugin Add new button
c. Upload WP Disable Automatic Updates plugin (Not see any update list)
3. Active WP Disable Automatic Updates Plugin
4. Check-in Dashboard > Updates

Note: If you want to check any update in your WordPress site. You need to deactivate WP Disable Automatic Updates Plugin.










Saturday, 1 February 2020

How to disable automatic updates in wordpress?



Write below code in current WordPress themes in function.php

/wp-content/themes/twentytwenty/functions.php
/* Disable Automatic Updates in WordPress */
function remove_core_updates(){
global $wp_version;return(object) array('last_checked'=> time(),'version_checked'=> $wp_version,);
}
add_filter('pre_site_transient_update_core','remove_core_updates');
add_filter('pre_site_transient_update_plugins','remove_core_updates');
add_filter('pre_site_transient_update_themes','remove_core_updates');
/* .Disable Automatic Updates in WordPress */

Tuesday, 3 September 2019

How to Replace Text of the_content in WordPress

If you want to replace keywords and text in the_content? Add the following code to the functions.php file of your WordPress active theme OR in custom plugin.

<?php
function replace_text($text) {
    $text = str_replace('Have a coupon?', 'Haben Sie einen Gutschein?', $text);
    $text = str_replace('Apply Coupon', 'Gutschein anwenden', $text);
    $text = str_replace('Product', 'Produkt', $text);
    $text = str_replace('Price', 'Preis', $text);
    $text = str_replace('Coupon code', 'Gutschein Code', $text);
    $text = str_replace('Update Cart', 'Warenkorb aktualisieren', $text);
    $text = str_replace('Billing Details', 'Rechnungsdetails', $text);
    $text = str_replace('Additional Information', 'Zusätzliche Informationen', $text);
    $text = str_replace('Your order', 'Ihre Bestellung', $text);
    $text = str_replace('Shipping address', 'Lieferadresse', $text);
   
    return $text;
}
add_filter('the_content', 'replace_text',99);
?>

Friday, 2 November 2018

reCAPTCHA V3 Example in PHP


<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
## reCAPTCHA V3 key define ##
#client-side
define('RECAPTCHA_SITE_KEY', 'reCAPTCHA_site_key'); // define here reCAPTCHA_site_key
#server-side
define('RECAPTCHA_SECRET_KEY', 'reCAPTCHA_secret_key'); // define here reCAPTCHA_secret_key

class Captcha {
public function getCaptcha($SecretKey) {
$data = array(
'secret' => RECAPTCHA_SECRET_KEY,
'response' => $SecretKey
);
$verify = curl_init();
curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($verify, CURLOPT_POST, true);
curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
$response_data = curl_exec($verify);
$response_data = json_decode($response_data);
curl_close($verify);
//echo "<pre>"; print_r($response_data); echo "</pre>";
return $response_data;
}
}

///////////////////////////// OR /////////////////////////////
/*
class Captcha {
public function getCaptcha($SecretKey) {
$Resposta = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . RECAPTCHA_SECRET_KEY . "&response={$SecretKey}");
$Retorno = json_decode($Resposta);
return $Retorno;
}
}
*/

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//echo "<pre>"; print_r($_REQUEST); echo "</pre>";
$ObjCaptcha = new Captcha();
$Retorno = $ObjCaptcha->getCaptcha($_POST['g-recaptcha-response']);
//echo "<pre>"; print_r($Retorno); echo "</pre>";
if ($Retorno->success) {
echo '<p style="color: #0a860a;">CAPTCHA was completed successfully!</p>';
} else {
$error_codes = 'error-codes';
if (isset($Retorno->$error_codes) && in_array("timeout-or-duplicate", $Retorno->$error_codes)) {
$captcha_msg = "The verification expired due to timeout, please try again.";
} else {
$captcha_msg = "Check to make sure your keys match the registered domain and are in the correct locations.<br> You may also want to doublecheck your code for typos or syntax errors.";
}
echo '<p style="color: #f80808;">reCAPTCHA error: ' . $captcha_msg . '</p>';
}
}
?>

<div class="contact_form">
<div class="" style="margin-top:0px;margin-bottom:15px;">
<div class="" style="width:50%">
<form id="Form1" name="Form1" action="" method="POST">
<label for="fname">First Name*</label><br>
<input type="text" name="fname" id="fname" required autofocus><br><br>

<label for="lname">Last Name*</label><br>
<input type="text" name="lname" id="lname" required><br><br>

<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"><br>
<input type="submit">
</form>
</div>
</div>
</div>

<script src="https://www.google.com/recaptcha/api.js?render=<?php echo RECAPTCHA_SITE_KEY; ?>"></script>
<script>
grecaptcha.ready(function () {
grecaptcha.execute('<?php echo RECAPTCHA_SITE_KEY; ?>', {action: 'homepage'}).then(function (token) {
document.getElementById('g-recaptcha-response').value = token;
});
});
</script>
</body>
</html>

Wednesday, 20 June 2018

Why type="file" does not Work with Safari Browser? in Contact Form 7


Note: Script Must be written in header

<script>
jQuery(function() {
var input_file = [];
jQuery('form.wpcf7-form').on('submit', function() {
console.log("-------------------------------");
var i = 0;
jQuery('input[type=file]').each(function() {
if (jQuery(this).val() === '') {
jQuery(this).attr('type', 'hidden');
input_file[i++] = jQuery(this).attr('name');
}
});
console.log("Type Change File To Hidden: "+input_file);
});

jQuery( document ).ajaxComplete(function() {
//AJAX RESPONSES
console.log("Array in File item: "+input_file.length);
if(input_file.length > 0){
jQuery.each(input_file, function(key, index){
console.log("Type Change Hidden To File: "+key +'=> '+index);
jQuery('input[name='+input_file[key]+']').attr('type', 'file');
});
input_file = [];
}
console.log("Response: " + jQuery(".wpcf7-response-output").html());
});
});
</script>

Please try this and give your review.

Monday, 16 April 2018

How To Create Shortcode In WordPress with parameters?



<?php
### the shortcode code add in theme’s functions.php file  ###
// "do_shortcode" but without the wrapping <p> of Shortcodes
function do_shortcode_boc($content) {
 $array = array (
        '<p>[' => '[',
        ']</p>' => ']',
        ']<br />' => ']'
    );
$content = strtr($content, $array);
$content = do_shortcode($content);
    return $content;
}

function shortcode_shortcodename($atts, $content = null) {   
$atts = shortcode_atts(
array(
'title' => '',
'image' => '',
        ), $atts);

$title = $atts['title'] ? $atts['title'] : '';
$image = $atts['image'] ? $atts['image'] : '';

$str = '<li>
<div class="icon_item">
<img src="'.$image.'">
<p>'.html_entity_decode($title).'</p>
<div class="icon_overlay">
<p>'.do_shortcode($content).'</p>
</div>
</div>
</li>';
return $str;
}
add_shortcode('shortcodename', 'shortcode_shortcodename');

?>

##### Using below code to display shortcode detail  #####

[shortcodename title="my title" image="example.jpg"]
<div>
<p> Shortcode content </p>
</div>
[/shortcodename]

##### OR #####

<?php
echo do_shortcode('[shortcodename]');
?>

Friday, 29 December 2017

Contact Form 7 Data POST


How to pass/post Contact Form 7 Data another storage or API?

Download  Contact Form 7 Data POST Plugin and write your custom code in plugin file then you can pass data easily...🌝


Monday, 25 September 2017

Uncaught Error: Syntax error, unrecognized expression: [href=#] in ordpress




To temporarily solution
Until your theme developers release a fixed version,
you can add the following code snippet into your theme functions.php file

------------------------------------------------------------------------------------

add_action( 'wp_enqueue_scripts', 'load_old_jquery', 100 );
function load_old_jquery() {
if ( ! is_admin() ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', ( "//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" ), false, '1.11.3' );
wp_enqueue_script( 'jquery' );
}
}

Saturday, 9 September 2017

Add Overlay on Contact Form 7 Submit Button

=> Add below script in Wordpress Footer

<script type="text/javascript">
jQuery(document).ready(function (){
// Contact Form 7 Submit Button Overlay
var OriginalSubmitValue;
jQuery('.wpcf7-submit').on('click', function () {
OriginalSubmitValue = jQuery(this).val();
jQuery(this).val('Processing ...');
/*setTimeout(function(){jQuery('.wpcf7-submit').attr('disabled','disabled');},1000);*/
jQuery("body").after('<div id="quoteformloadingscreen" style="background: rgba(0, 0, 0, 0.4);position: fixed;top: 0;left: 0;z-index: 999999;width: 100%;height: 100%;overflow-y: hidden;overflow: hidden;"></div>');
});

// Hide new spinner on result
jQuery('div.wpcf7').on('wpcf7:invalid wpcf7:spam wpcf7:mailsent wpcf7:mailfailed', function () {
//jQuery('.ajax-loader-custom').css({ visibility: 'hidden' });
//jQuery('.wpcf7-submit').prop('disabled', false);
jQuery('.wpcf7-submit').val(OriginalSubmitValue);
jQuery("#quoteformloadingscreen").remove();
});
});
</script>

Wednesday, 9 August 2017

Gravity Form In Prevent duplicate form submit on back button

jQuery(function($){
       $(document).on('gform_post_render', function(e, form_id){
            $('#gform_ajax_frame_'+form_id).attr('src', 'about:blank');
       });
});

Friday, 12 May 2017

Featured Image Get in Wordpress

<?php
if(is_home()){
   $blog_page = get_option( 'page_for_posts' );
   $src = wp_get_attachment_image_src( get_post_thumbnail_id($blog_page), 'full' );
$Featured_Image = 'style="background-image: url('.$src[0].');"';
}
?>
<div class="" <?php echo $Featured_Image; ?>></div>

Tuesday, 3 January 2017

WooCommerce: Add wordpress custom field Tab on the Product Page

<?php

/* ## WooCommerce: Add wordpress custom field Tab on the Product Page ## */

/*--------------- Add belove code in theme's function.php file --------------*/



/* Add custom field description tab in Product page */

add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );

function woo_new_product_tab( $tabs ) {
   
$tabs['product_short_description'] = array(
    'title'     => __( 'Ingredients', 'woocommerce' ),
    'priority'  => 50,
    'callback'  => 'woo_new_product_tab_content'
);
    return $tabs;
}


function woo_new_product_tab_content() {
echo get_post_meta(get_the_ID(), 'custom_field_name', TRUE); // Add here custom field name
}

/*. Add custom field description tab in Product page */
?>

Monday, 12 December 2016

SSL certificate problem: unable to get local issuer certificate in Wordpress Update

Wordpress in Plugins or Wordpress version issue by

SSL certificate problem: unable to get local issuer certificate


Resolved:
Add belove two lina at bouttom in "wp-config.php" file

add_filter('https_ssl_verify', '__return_false');
add_filter('https_local_ssl_verify', '__return_false');