Skip to content

Instantly share code, notes, and snippets.

@jaredatch
jaredatch / functions.php
Last active October 12, 2024 21:26
WordPress Search Autocomplete using admin-ajax.php
<?php
/**
* Enqueue scripts and styles.
*
* @since 1.0.0
*/
function ja_global_enqueues() {
wp_enqueue_style(
'jquery-auto-complete',
@yanknudtskov
yanknudtskov / wp-rest-api-example.php
Last active October 20, 2022 05:52
WordPress REST API Example #rest-api
<?php
function tomjn_rest_test() {
return "moomins";
}
add_action( 'rest_api_init', function () {
register_rest_route( 'tomjn/v1', '/test/', array(
'methods' => 'GET',
'callback' => 'tomjn_rest_test'
@bebaps
bebaps / rest-api-loop.php
Created February 22, 2017 01:26
Standard loop of posts using the WP REST API
<?php
// Standard API query arguments
$args = array(
'orderby' => 'title',
'per_page' => 3
);
// Put into the `add_query_arg();` to build a URL for use
// Just an alternative to manually typing the query string
$url = add_query_arg( $args, rest_url('wp/v2/posts') );
@myshov
myshov / function_invocation.js
Last active August 19, 2024 12:23
11 Ways to Invoke a Function
console.log(1);
(_ => console.log(2))();
eval('console.log(3);');
console.log.call(null, 4);
console.log.apply(null, [5]);
new Function('console.log(6)')();
Reflect.apply(console.log, null, [7])
Reflect.construct(function(){console.log(8)}, []);
Function.prototype.apply.call(console.log, null, [9]);
Function.prototype.call.call(console.log, null, 10);
@devinsays
devinsays / example-ajax-enqueue.php
Last active January 27, 2025 15:51
Simple WordPress Ajax Example
<?php
function example_ajax_enqueue() {
// Enqueue javascript on the frontend.
wp_enqueue_script(
'example-ajax-script',
get_template_directory_uri() . '/js/simple-ajax-example.js',
array( 'jquery' )
);
@mrmartineau
mrmartineau / gitcom.md
Created November 18, 2017 22:33 — forked from jednano/gitcom.md
Common git commands in a day-to-day workflow

Git Cheat Sheet

Initial Setup

Create an empty git repo or reinitialize an existing one

$ git init
@mtx-z
mtx-z / wp-bootstrap4.4-pagination.php
Last active January 16, 2025 16:15
Wordpress 5.4 Bootstrap 4.4 pagination (with custom WP_Query() and global $wp_query support) (UPDATED for Bootstrap 5: https://gist.github.com/mtx-z/af85d3abd4c19a84a9713e69956e1507)
<?php
/**
* @param WP_Query|null $wp_query
* @param bool $echo
* @param array $params
*
* @return string|null
*
* UPDATE for Bootstrap 5.0: https://gist.github.com/mtx-z/af85d3abd4c19a84a9713e69956e1507
*
@mrmartineau
mrmartineau / dev-resources.md
Last active March 23, 2023 00:20
My go-to resources for working on the web.
@kmwalsh
kmwalsh / gist:b02acf86d05ccd1767ea9fc4c261bff5
Last active May 12, 2022 17:50
Redirect single post to external link - WordPress
/**
* =============================================================
* Redirect single post to external link
* =============================================================
*/
// this checks to make sure that the function doesn't already exist
// if something else in your WP uses a function named redirect_cpt_to_external_link
// this check to see whether it exists or not will keep your site from crashing
if ( ! function_exists('redirect_cpt_to_external_link') ) {
@neckerson
neckerson / theme.js
Last active June 10, 2019 03:47
Expose jQuery $ in the window so it can be accessed by jQuery plugins
// In the root directory of the theme, install your plugin:
//
// > yarn add jquery-zoom
//
// Add the line below to the top of scripts/layout/theme.js
import $ from 'jquery';
// Below your imports, set up jQuery so that it can be accessed
// from the HTML