Skip to content

Instantly share code, notes, and snippets.

/* Ajax Function */
add_action("wp_ajax_my_ajax_action", "my_ajax_handler");
add_action("wp_ajax_nopriv_my_ajax_action", "my_ajax_handler");
function my_ajax_handler() {
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
<?php
/*
Template Name: Ajax Demo
*/
<h3>Simple AJAX in Wordpress Demo</h3>
<button id="triggerajax" onclick="fetchposts()">Click to Fetch Posts</button>
<div id="postcontainer"></div>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "http://www.example.com",
"name": "Unlimited Ball Bearings Corp.",
"contactPoint": {
"@type": "ContactPoint",
"telephone": "+1-401-555-1212",
"contactType": "Customer service"
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
ssh -i /path/my-key-pair.pem my-instance-user-name@my-instance-public-dns-name
function sendEmails() {
var emailAddress = 'someone@example.com';
var subject = 'Subject Line';
var message = 'Your message here';
MailApp.sendEmail(emailAddress, subject, message, {
htmlBody: message,
cc : 'cc@example.com',
bcc : 'bcc@example.com'
});
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
#force https:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
#Force http:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]