Skip to content

Instantly share code, notes, and snippets.

@aaronsummers
aaronsummers / Contact form 7 form builder shortcodes
Last active December 18, 2023 19:45
Contact form 7 all fields and country dropdown
[text text class:classname class:otherclassname placeholder "placeholder"]
[email* email placeholder "Email Address"]
[url* url placeholder "http://..."]
[tel* tel placeholder "Phone no."]
[range* number-slider min:0 max:100 placeholder "Ammount"]
[number* number-spinbox min:0 max:100 placeholder "Ammount"]
@aaronsummers
aaronsummers / checkbox.js
Created March 23, 2018 10:34
Custom checkbox style for contact form 7
$('.wpcf7-acceptance label').on('click', function(event) {
if($('input[type=checkbox]').attr('checked')) {
$(this).toggleClass('checked');
}
});
@aaronsummers
aaronsummers / gulpfile.js
Created April 4, 2018 11:01
WordPress theme development Gulp workflow
/*
If you're using this file, you'll need to update
* Directories
* FTP details (59, 60, 61)
* Scripts paths (105, 106)
* + watch directories (135)
*/
@aaronsummers
aaronsummers / Add custom admin notification to custom post type admin screen.php
Last active June 28, 2018 10:13
WordPress - Add custom admin notification to custom post type admin screen
<?php
function support_admin_notice() {
// https://codex.wordpress.org/Function_Reference/get_current_screen
$screen = get_current_screen();
// echo '<pre>' . var_export($screen, true) . '</pre>'; // View screen dump
//If not on the screen with post_type 'support' abort.
if( $screen->post_type !='support' )
return;
@aaronsummers
aaronsummers / Contact form 7 events.js
Last active May 16, 2018 07:41
Contact form 7 event listeners
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = '<?php echo site_url('/success/')?>';
}, false );
document.addEventListener( 'wpcf7submit', function( event ) {}
/*
List of Contact Form 7 Custom DOM Events
wpcf7invalid — Fires when an Ajax form submission has completed successfully, but mail hasn’t been sent because there are fields with invalid input.
wpcf7spam — Fires when an Ajax form submission has completed successfully, but mail hasn’t been sent because a possible spam activity has been detected.
@aaronsummers
aaronsummers / Adding search query parameter to new WP_Query .php
Last active June 28, 2018 10:12
Adding search query parameter to new WP_Query
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => array('post', 'page', 'custom_post_type'),
'posts_per_page' => 12,
'paged' => $paged,
's' => $s, // $s ADDS IN THE SEARCH QUERY
);
@aaronsummers
aaronsummers / Adding pagination to custom archives.php
Last active April 18, 2019 07:49
Adding pagination to custom post type archives
<?php
global $wp_query;
// Make Pages work with the loop
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// Args
$args = array(
'post_type' => 'custom_post_type',
'posts_per_page' => 8,
@aaronsummers
aaronsummers / Remove admin sidebar items.md
Last active April 16, 2018 08:45
Debug wordpress admin sidebar

Thanks to this post

You need to use the right hooks (which are not always the same as the URLs/slugs), and it doesn't hurt to use a hook that runs later (e.g., admin_init):

add_action( 'admin_init', 'wpse_136058_remove_menu_pages' );

function wpse_136058_remove_menu_pages() {

    remove_menu_page( 'edit.php?post_type=acf' );
@aaronsummers
aaronsummers / hide-folders-sublime-sidebar.md
Last active April 3, 2019 10:00
Hide WordPress core files from Sublime editor

project_name.sublime-project

Add the folders and files to your sublime-project file to exclude them from the sidebar.

{
 "folders": [
	{
	 "folder_exclude_patterns": [
 "wp-includes",
@aaronsummers
aaronsummers / Loading JavaScript and Stylesheet Only When it is Necessary in contact form 7 .md
Last active June 6, 2018 13:36
Loading JavaScript and Stylesheet Only When it is Necessary in contact form 7

Source

In its default settings, Contact Form 7 loads its JavaScript and CSS stylesheet on every page. You might think it would be redundant or wasteful, and want to load them only on those pages that contain contact forms. I understand the feeling, but there is a technical difficulty for a plugin in knowing whether the page contains contact forms or not at the start of loading. However, I can show you a way to work around that.

Step 1: Stop loading the JavaScript and CSS stylesheet on all pages

When the value of WPCF7_LOAD_JS is set to false (default: true), Contact Form 7 does not load the JavaScript. You can set the value of this constant in your wp-config.php like this:

define('WPCF7_LOAD_JS', false);