Skip to content

Instantly share code, notes, and snippets.

@getneerajk
getneerajk / upload_size change.php
Last active September 25, 2023 08:55
Filter the upload size limit for non-administrators. #wp #medialibrary
<?php
/**
* Filter the upload size limit for non-administrators.
*
* @param string $size Upload size limit (in bytes).
* @return int (maybe) Filtered size limit.
*/
function filter_site_upload_size_limit( $size ) {
// Set the upload size limit to 10 MB for users lacking the 'manage_options' capability.
if ( ! current_user_can( 'manage_options' ) ) {
@getneerajk
getneerajk / si_native_share.php
Last active December 5, 2023 06:45
Native share #wp #nativeshare
<?php
//This function outputs the html for the share button and popup
function si_share_this_page($id,$imgsrc){
?>
<img src="<?php echo $imgsrc;?>" alt="Share icon" id="si-share-button" class="share-icon si-share-button " >
<div class="share-link-popup" id="si-share-link-popup">
<div class="si-share-link-popup-head" >
<p> Share this Page</p>
<button id="si-share-link-popup-close" >X</button>
@getneerajk
getneerajk / validate_comment_email.js
Last active December 1, 2023 04:12
Comment email validation alert #wp #js #comment #email
// comment section email validation start
document.addEventListener('DOMContentLoaded', function() {
var commentForm = document.getElementById('commentform'); // Replace 'commentform' with the ID of your comment form
if (commentForm) {
var emailField = commentForm.querySelector('input[name="email"]');
commentForm.addEventListener('submit', function(event) {
var emailValue = emailField.value.trim();
@getneerajk
getneerajk / faq.css
Last active November 7, 2023 12:58
FAQ accordion #faq #wp
/* FAQ Section Mobile*/
html{
font-size: calc(100vw * 18/360);
}
.faq-container{
position: relative;
padding-top: 1.667rem;
}
.faq-content{
@getneerajk
getneerajk / tax_sync.php
Created November 8, 2023 13:07
Synchronize terms between the two taxonomies #taxonomy #wp
<?php
// Synchronize terms between the two taxonomies
function synchronize_taxonomies( $term_id, $tt_id, $taxonomy ) {
if (in_array($taxonomy, array('first_taxonomy', 'second_taxonomy'))) {
$term = get_term($term_id, $taxonomy);
$other_taxonomy = ($taxonomy === 'first_taxonomy') ? 'second_taxonomy' : 'first_taxonomy';
// Check if the term exists in the other taxonomy
$term_exists = term_exists($term->name, $other_taxonomy);
@getneerajk
getneerajk / csp.php
Created November 15, 2023 03:58
Set csp headers #wp
<?php
// Add a filter to modify the HTTP headers
function add_csp_header() {
header("Content-Security-Policy: default-src 'self'; script-src 'self' https://example.com; style-src 'self' https://example.com;");
// Add more directives as needed based on your specific requirements
}
// Hook the function to the 'send_headers' action
add_action('send_headers', 'add_csp_header');
@getneerajk
getneerajk / single_image_uploads_dir.php
Last active September 21, 2024 21:01
WP All Import Pro upload image to its original path #wp #WP_All_Import_Pro
<?php
add_filter( 'wp_all_import_single_image_uploads_dir', 'wpai_wp_all_import_single_image_uploads_dir', 10, 6 );
function wpai_wp_all_import_single_image_uploads_dir( $uploads, $image_url, $articleData, $current_xml_node, $import_id, $post_id ) {
$position = strpos($image_url, 'uploads');
$result = substr($image_url, $position + 7,8); //eg: `/2021/05`
$uploads['path'] = $uploads['basedir'].$result;
$uploads['url'] = $uploads['baseurl'].$result;
$uploads['subdir']=$result;
@getneerajk
getneerajk / search_result_count.php
Created December 1, 2023 03:59
Search result count #wp #search
<?php
$query_cpt = new WP_Query($args);
$posts_per_page = $query_cpt->query_vars['posts_per_page'];
$posts_found = $query_cpt->found_posts;
$paged = $query_cpt->query_vars['paged'];
if ( $posts_found ) {
$start_result = ( $paged - 1 ) * $posts_per_page + 1;
@getneerajk
getneerajk / safari_ios_check.js
Created February 13, 2024 07:05
Check if current browser is Safari iOS
var ua = window.navigator.userAgent;
var iOS = ua.match(/iPad/i) || ua.match(/iPhone/i);
var webkit = ua.match(/WebKit/i);
var iOSSafari = iOS && webkit && !ua.match(/CriOS/i);
console.log("ios: "+ iOS + " | webkit: "+ webkit +" | ios safari: "+ iOSSafari);
@getneerajk
getneerajk / animate_count.js
Created February 16, 2024 09:06
Animate numbers count #animation #count #js
document.addEventListener("DOMContentLoaded", function() {
/* animate counter
* <span class="animate-count">1000</span>
*/
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();