Skip to content

Instantly share code, notes, and snippets.

View uprise10's full-sized avatar

Arjan Snaterse uprise10

View GitHub Profile
@uprise10
uprise10 / prevent-click-click-in-gf.php
Created May 25, 2021 19:05
Prevent double click on submit button in Gravity Forms
<?php
add_action( 'gform_enqueue_scripts', 'your_prefix_add_scripts' );
function your_prefix_add_scripts($form) {
echo '<script>
document.addEventListener( "DOMContentLoaded", function( e ) {
if ( typeof jQuery !== "undefined" ) {
jQuery(document).on( "click", "#gform_' . $form['id'] . ' [type=submit]", function(e) {
if( jQuery(this).data("isclicked" ) === true ) {
e.preventDefault();
<?php
$args_cpt = [
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => [
'slug' => 'test-cpt',
'with_front' => true,
<select>
<option value="Africa/Algiers">Africa/Algiers</option>
<option value="Africa/Cairo">Africa/Cairo</option>
<option value="Africa/Casablanca">Africa/Casablanca</option>
<option value="Africa/Harare">Africa/Harare</option>
<option value="Africa/Nairobi">Africa/Nairobi</option>
<option value="America/Argentina/Buenos_Aires">America/Argentina/Buenos_Aires</option>
<option value="America/Belize">America/Belize</option>
<option value="America/Bogota">America/Bogota</option>
<option value="America/Boise">America/Boise</option>
@uprise10
uprise10 / gravity-forms-azurre-storage.php
Created March 8, 2019 12:52
When using Gravity Forms and the Microsoft Azure Storage plugin, uploaded files via a form are not automatically uploaded to Azure. This piece of code fixes that.
<?php
class Radish_GF_Azure_HandleUploads {
private static $instance;
public function __construct() {
$this->run();
}
@uprise10
uprise10 / exclude-noindex-posts-from-search.php
Created July 31, 2018 11:03
This piece of code excludes posts from the WordPress search which have the robots meta settings on noindex, following the Yoast SEO settings.
<?php
add_action( 'pre_get_posts', function( \WP_Query $query ) {
if( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
$meta_query = [
'relation' => 'OR',
[
'key' => '_yoast_wpseo_meta-robots-noindex',
'value' => '1',
'compare' => '!=',
@uprise10
uprise10 / exclude-author-xml-stiemap.php
Created November 16, 2017 14:02
Exclude author XML sitemap from Yoast SEO
<?php
add_filter( 'wpseo_sitemap_exclude_author', function () {
return [];
});
@uprise10
uprise10 / wp-popular-posts.php
Last active April 18, 2017 07:37
WordPress Popular posts via AJAX
@uprise10
uprise10 / change-db-dollation.php
Created September 19, 2016 08:35
Change DB collation of all tables and columns
<?php
$database_name='';
$database_username='';
$database_password='';
$connection = mysqli_connect('localhost',$database_username,$database_password);
if(!$connection) {
echo "Cannot connect to the database – incorrect details";
@uprise10
uprise10 / gist:e5350edf222c21430729
Last active August 29, 2015 14:23
WordPress: custom number of posts for homepage only
<?php
/**
* This piece of code let you use a different number of posts for the homepage, than the default posts_per_page setting.
*/
add_action( 'pre_get_posts', 'yourprefix_filter_posts' );
add_filter('found_posts', 'yourprefix_adjust_offset_pagination', 1, 2 );
$posts_on_homepage = 7; // Custom number of posts for the homepage
<?php
// Put this in your functions.php or in a separate plugin if you want to show all locaitons on one page
add_action( 'pre_get_posts', 'wpseo_local_show_all_locations' );
function wpseo_local_show_all_locations( $query ) {
if( false == $query->is_main_query() || false == is_post_type_archive( 'wpseo_locations' ) ) {
return;
}
$query->set( 'posts_per_page', -1 );