Skip to content

Instantly share code, notes, and snippets.

View faisalahammad's full-sized avatar
🎯
Focusing

Faisal Ahammad faisalahammad

🎯
Focusing
View GitHub Profile
@faisalahammad
faisalahammad / ninja-forms-elementor-pro-recaptcha-v3-fix.php
Created July 9, 2025 14:26
PHP snippet to fix Google reCaptcha v3 loading issue in Ninja Forms with Elementor Pro. This workaround ensures proper reCaptcha script enqueue using Ninja Forms settings and supports multilingual options. Ideal for WordPress developers facing reCaptcha conflicts between Ninja Forms and Elementor Pro plugins.
<?php
/**
* Fix Google reCaptcha v3 loading issue in Ninja Forms with Elementor Pro.
*
* @author Faisal Ahammad <[email protected]>
*/
add_filter('ninja_forms_pre_enqueue_recaptcha_v3_js', 'nfele_enqueue_recaptcha_v3_js');
function nfele_enqueue_recaptcha_v3_js()
@faisalahammad
faisalahammad / ninja-forms-set-default-hour-in-date-time-field.js
Created July 9, 2025 12:52
Use this jQuery script to automatically set the default selected option to "09" for hour dropdowns in Ninja Forms plugin Date/Time field. This code waits until elements with class `.setdefaulttime` appear on the page, then targets `<select>` elements with IDs starting with `hour-select-` or class `.hour.extra` and selects the option with value "…
/**
* Set default hour to 09:00 for date/time fields in Ninja Forms
*
* @author Faisal Ahammad <[email protected]>
*
* First add the "setdefaulttime" CSS class in the Date/Time → Display → Container to make this code work.
*/
jQuery(document).ready(function($) {
function checkAndSetHour() {
@faisalahammad
faisalahammad / gravity-forms-apc-auto-resave.php
Created July 8, 2025 17:23
Automatically re-saves posts created via Gravity Forms Advanced Post Creation add-on after 5 and 10 seconds to fix social sharing image issues. Includes force cron functionality for testing.
<?php
/**
* Gravity Forms Advanced Post Creation Auto Resave
*
* This code automatically resaves posts created by the Gravity Forms Advanced Post Creation add-on.
* It ensures that the post is properly saved and updated in the database.
* Visit https://yoursite.com/?force_cron if the code doesn’t run automatically. This URL will force the cron to run.
*
* @author Faisal Ahammad <[email protected]>
*/
@faisalahammad
faisalahammad / gravityforms-redirect-to-created-post.php
Created July 8, 2025 12:51
This snippet demonstrates how to automatically redirect users to the newly created post after submitting a Gravity Forms form using the Advanced Post Creation add-on in WordPress. Perfect for guest post submissions, this code ensures users are sent directly to their published post upon form submission.
<?php
/**
* Gravity Forms: Redirect to Newly Created Post After Submission
*
* @author Faisal Ahammad <[email protected]>
*
* Replace 123 with your actual Gravity Form ID.
*/
add_filter( 'gform_confirmation_123', 'gfapc_redirect_to_created_post', 10, 4 );
@faisalahammad
faisalahammad / ninja-forms-select-image-rearrange-label-image-position.js
Created June 2, 2025 17:18
A jQuery script to rearrange images and labels for the Select Image field in Ninja Forms. This code ensures images appear above the label text by swapping their positions dynamically. It waits for Ninja Forms to fully load before applying the changes, adds a 5px bottom margin to images, and is optimized for WordPress compatibility.
/**
* Rearranges label and image elements in the Select Image field
* @author Faisal Ahammad <[email protected]>
*/
jQuery(document).ready(function ($) {
function waitForLabels() {
if ($(".listimage-container label").length) {
$(".listimage-container label").each(function () {
var $this = $(this);
@faisalahammad
faisalahammad / ninja-forms-change-placeholder-text-color.css
Created May 1, 2025 10:40
A simple way to change the placeholder text color in your form fields by adding CSS in Field Name → Styles → Wrap Styles → Advanced CSS, making sure to enable the "Show Advanced CSS Properties" option. The example CSS covers different browsers and lets you customize the placeholder text color by changing the color code. Please note that to add c…
input::placeholder {
color: #000;
}
input::-webkit-input-placeholder {
color: #000;
}
input::-moz-placeholder {
color: #000;
@faisalahammad
faisalahammad / gravity-forms-multilingual-required-text.php
Created April 24, 2025 17:25
Custom WordPress code to display different "required fields" text for different Gravity Forms. Perfect for multilingual websites that need form validation messages in multiple languages. Just modify the form IDs and customize the text for each language you need. Add to your theme's functions.php file or use with a code snippets plugin.
<?php
/**
* Add multilingual support for required field text in Gravity Forms
*
* @author Faisal Ahammad <[email protected]>
*/
add_filter( 'gform_required_legend', 'dynamic_required_legend', 10, 2 );
function dynamic_required_legend( $legend, $form ) {
$form_id = $form['id'];
@faisalahammad
faisalahammad / restrict-foreign-characters-gravity-forms.php
Created April 18, 2025 12:38
Simple PHP code to restrict Gravity Forms fields to English letters, numbers, spaces, and basic punctuation only. Prevents foreign characters on form submission.
<?php
add_filter('gform_field_validation', function($result, $value, $form, $field) {
// Specify the field IDs you want to restrict (example: 1, 2)
$restricted_field_ids = [1, 2];
if (in_array($field->id, $restricted_field_ids)) {
// If value is an array (like Name field), convert it to a string
if (is_array($value)) {
$value = implode(' ', $value);
}
@faisalahammad
faisalahammad / gravity-forms-placeholder-asterisk.php
Created April 13, 2025 05:42
This snippet auto-appends an asterisk to the placeholder text of required fields in Gravity Forms. It ensures that only fields with placeholders are modified, and prevents double-adding asterisks.
<?php
function gw_required_placeholder_asterisk( $form ) {
foreach ( $form['fields'] as &$field ) {
// Skip fields that don't support placeholders
if ( ! is_callable( [ $field, 'get_entry_inputs' ] ) ) {
continue;
}
// Single input fields
if ( is_array( $field->inputs ) ) {
@faisalahammad
faisalahammad / replace-thumbnails-with-fullsize-images.php
Last active February 27, 2025 15:07
This code snippet uses jQuery to replace product thumbnail images with their full-size versions in the WordPress admin products list page. It ensures that whenever the page loads or the product list is refreshed, the thumbnails are updated to show larger images.
<?php
/**
* Use jQuery to replace product thumbnails with full-size images in admin
* @author: Faisal Ahammad
*/
function replace_admin_thumbnails_with_fullsize_js() {
$screen = get_current_screen();
if (!$screen || $screen->base !== 'edit' || $screen->post_type !== 'product') {
return;
}