<script>
jQuery(document).ready(function(){
window.history.replaceState(null, null, window.location.pathname);
});
</script>
Author: Avinash Konanki
HTML button for Google Calendar
<a href="https://calendar.google.com/calendar/render?action=TEMPLATE&text=Avi Web Event&details=Event details&dates=20220720T053000/20220725T073000&location=Online" target="_blank">Add to Calendar</a>
OWL carousel items overlapping
.owl-carousel .animated {
-webkit-animation-duration: 20ms;
animation-duration: 20ms;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
How to create a custom table using custom code in WordPress?
global $wpdb;
global $charset_collate;
$table_name = $wpdb->prefix . 'custom_table';
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
`ID` int(20) NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
`mobile_number` varchar(200) NOT NULL,
`email` varchar(20) NOT NULL,
PRIMARY KEY (`ID`)
)$charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
CF7 failed to load resource: the server responded with a status of 409 ()
<pre>
Add below code in function.php
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );
</pre>
Update custom taxonomy post number limits
<pre>
function aviweb_change_posts_per_page( $query ) {
if (is_tax( 'custom_taxonomy' ) ) {
$query->set( 'posts_per_page', 3 );
}
}
add_filter( 'pre_get_posts', 'aviweb_change_posts_per_page' );
</pre>
Validate URL using jQuery
var url = "https://avinashkonanki.com/";
var url_validate = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
if(!url_validate.test(url)){
alert('error');
}
else{
alert('success');
}
Encryption & Decryption using PHP
<pre>
//Encryption
function encryption_function($string){
// Storingthe cipher method
$ciphering = "AES-128-CTR";
// Using OpenSSl Encryption method
$iv_length = openssl_cipher_iv_length($ciphering);
$options = 0;
// Non-NULL Initialization Vector for encryption
$encryption_iv = '0000111122223333';
// Storing the encryption key
$encryption_key = "aviweb";
return openssl_encrypt($string, $ciphering, $encryption_key, $options, $encryption_iv);
}
//Decryption
function decryption_function($string){
// Storingthe cipher method
$ciphering = "AES-128-CTR";
// Using OpenSSl Encryption method
$iv_length = openssl_cipher_iv_length($ciphering);
$options = 0;
// Non-NULL Initialization Vector for encryption
$decryption_iv = '0000111122223333';
// Storing the decryption key
$decryption_key = "aviweb";
return openssl_decrypt($string, $ciphering, $decryption_key, $options, $decryption_iv);
}
</pre>
Compare two dates in php
<pre>
<?php
$date = "2021-12-25";
$today = date("Y-m-d");
$today_time = strtotime($today);
$compare_date = strtotime($date);
if($compare_date > $today_time){
echo 'Future date';
}else{
echo 'Past Date';
}
?>
</pre>
How to get taxonomy acf data in WordPress
<pre>
$terms = get_the_terms( get_the_ID(), 'custom_taxonomy' );
<?php foreach( $terms as $term ){
$image = get_field('image', $term->taxonomy . '_' . $term->term_id);
} ?>
</pre>