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




Tuesday 11 August 2020

How To Search In PHP Array Element Containing String | Like Binod


$example = array(
        "who" => "Who is Binod?",
        "name" => "Dose Binod Tharu is Binod?",
"where" => "Where is Binod?",
"whose" => "Whose name is binod?",
"YouTube" => "Dose Binod in the YouTube?",
"meaning" => "What is Binod meaning?",
"fullform" => "What is Binod full form?",
"pronunciation" => "What is Binod pronunciation?",
"english" => "Dose Vinod in english",
"how" => "How to write Vinod in sanskrit?",
"nickname" => "Which best nickname for Vinod?",
"kon" => "Binod kon he?",
"kaha" =>"Binod kaha he?",
"kiska" =>"Binod kiska name he?"
);

$searchword = 'Binod';

$search_results = array_filter($example, function($var) use ($searchword) {
return preg_match("/\b$searchword\b/i", $var); 
});

echo "Search Word: ".$searchword;
echo "<br>Search Results";
echo "<pre>";
echo "Total Search: ".count($search_results);
echo "<hr>";
print_r($search_results);
echo "</pre>";

OutPut:

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.










Monday 18 May 2020

The best way to detect a mobile device



<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
var isMobile = false;
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// some code write for mobile device...
isMobile = true;
}else{
isMobile = false;
}
</script>
</head>
<body>
<div>
<center><h1 id="device"></h1></center>
</div>
<script>
if(isMobile){
jQuery("#device").text("This is mobile device...");
}else{
jQuery("#device").text("This is not mobile device...");
}
</script>
</body>
</html>



Output:

This is...

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 */

Wednesday 1 January 2020

How do I redirect to another webpage by jQuery?


There are many ways you can do page redirect to another webpage by jQuery.

Here I give you two example:
  1. Page redirect to another webpage on document ready by jQuery.
    <script>
    // Page redirect on document document
    jQuery(document).document( function() {
        // Similar behavior as an HTTP redirect
          window.location.replace("https://phpkishan.blogspot.com");  //OR
          window.location = "https://phpkishan.blogspot.com";  //OR
          window.location.href = "https://phpkishan.blogspot.com";  //OR
          window.location.assign("https://phpkishan.blogspot.com");
    }
    </script>

  2. Page redirect to another webpage on button clicking by jQuery.

    <button id="buttonID">Page redirect</button>

    <script>
    // Page redirect on button clicking
    jQuery(document).document( function() {
        jQuery( "#buttonID" ).click(function() {
            window.location.href = "https://phpkishan.blogspot.com/";
        });
    }
    </script>