Skip to content

Instantly share code, notes, and snippets.

View utkrishta's full-sized avatar

Utkrishta Adhikari utkrishta

View GitHub Profile
@utkrishta
utkrishta / get_filetime.php
Created October 14, 2020 00:48
Functions to get filetime in PHP and Javasript
<?php
$fileName = get_template_directory() . '/css/theme.css';
$modifiedDate = filemtime($fileName);
echo '<script>console.log(' . $modifiedDate . ')</script>';
?>
<script>
var fileName = "<?=home_url()?>/wp-content/themes/jims-aircon/css/theme.css";
var req = new XMLHttpRequest();
req.open("HEAD", fileName, false);
req.send(null);
@utkrishta
utkrishta / krish-related-posts.php
Created June 30, 2021 06:59
Plugin to add related posts within the contents
@utkrishta
utkrishta / metabox-repeater-fields.php
Created February 14, 2022 23:35
Displaying field values from metabox cloneable(repeater) fields
<?php
//get repeater field called 'services'
$services = rwmb_meta( 'services' );
if ( ! empty( $services ) ) {
foreach ( $services as $service ) {
//retrieve each values from subfield inside the services field
echo wp_get_attachment_image( $service['services_image'], 'full' );
echo $service['services_title'];
echo $service['services_description'];
//there is a repeater subfield within this called 'services_links'
<?php
/*
* We are using rank_math_locations custom post type. (or any other)
* Meta Box to create custom fields which saves in its own database table
* We have location metabox custom field saved in table "mbox_locations" and
* service type custom field saved in table "mbox_services"
*
* mbox_locations contains a sub-field(toggle) called capital-cities
* mbox_services contains a sub-field(radio) called service-type
*/
@utkrishta
utkrishta / contact.php
Created March 3, 2022 23:36
Display Days of the week and highlight current day
<div class="opening-hours">
<div class="row">
<div class="col-12"><h4>Our Business Hours</h4></div>
</div>
<div class="row" id="Sunday">
<div class="col-6 day">Sunday</div>
<div class="col-6 text-md-end hours">Open 24 Hrs</div>
</div>
<div class="row" id="Monday">
<div class="col-6 day">Monday</div>
@utkrishta
utkrishta / functions.php
Created April 8, 2022 01:49
Create a custom shortcode that calls and display content from another file/tempalate part
<?php
/*
* Create a custom shortcode that calls and display content from another file/tempalate part
*
* We have a file called custom-form.php inside inc folder which contains our custom form codes
*
*/
function custom_form( $atts, $content, $shortcode_tag ){
ob_start();
get_template_part('inc/custom-form');
@utkrishta
utkrishta / scripts.js
Created May 30, 2022 05:58
Pure Javascript to limit(hide) characters and show on clikc
window.addEventListener('load', function() {
const testimonialItems = document.querySelectorAll('.testimonial-item');
testimonialItems.forEach(testimonialItem => {
var maxLength = 200;
const textLength = testimonialItem.innerText.length;
if(textLength > maxLength) {
var shortContent = testimonialItem.innerText.substring(0, maxLength); /*split the content in two parts*/
var longContent = testimonialItem.innerText.substring(maxLength);
testimonialItem.innerHTML = shortContent + '<i class="read_more">...<strong> Read More</strong></i>';
const readbtn = testimonialItem.querySelectorAll('.read_more');