Skip to content

Instantly share code, notes, and snippets.

👨‍👦
I'd have more time for coding if I wasn't a parent!

Cameron Jones cameronjonesweb

👨‍👦
I'd have more time for coding if I wasn't a parent!
Block or report user

Report or block cameronjonesweb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cameronjonesweb
cameronjonesweb / add-post-thumbnail-to-rss.php
Last active Jul 22, 2018
Adds the post thumbnail to the WordPress RSS feed
View add-post-thumbnail-to-rss.php
<?php
add_action( 'rss2_item', 'cameronjonesweb_add_post_thumbnail_to_rss' );
function cameronjonesweb_add_post_thumbnail_to_rss() {
if ( has_post_thumbnail() ) {
printf(
"\t" . '<media:content url="%1$s" type="%2$s" />' . "\n",
esc_url( get_the_post_thumbnail_url() ),
esc_attr( get_post_mime_type( get_post_thumbnail_id() ) )
@cameronjonesweb
cameronjonesweb / prevent-roboto.js
Last active Jul 11, 2018
Prevent Google Maps from loading the Roboto font.
View prevent-roboto.js
var head = document.getElementsByTagName( 'head' )[0];
// Save the original method
var insertBefore = head.insertBefore;
// Replace it!
head.insertBefore = function( newElement, referenceElement ) {
if ( newElement.href && newElement.href.indexOf( 'https://fonts.googleapis.com/css?family=Roboto' ) === 0 ) {
return;
@cameronjonesweb
cameronjonesweb / salesforce-gravity-forms.php
Last active Jul 17, 2018
Updates the Salesforce API endpoint for the Gravity Forms Salesforce Add-On
View salesforce-gravity-forms.php
<?php
/**
* Updates the Salesforce API endpoint for the Gravity Forms Salesforce Add-On
* From the article Fixing The Gravity Forms Salesforce Add-On For WordPress: https://cameronjonesweb.com.au/blog/fixing-the-gravity-forms-salesforce-add-on-for-wordpress/
*
* @link https://help.salesforce.com/articleView?id=Updating-the-Web-to-Case-and-Web-to-Lead-Endpoint-URL&language=en_US&type=1
* @param string $sub The current subdomain (www or test).
* @param bool $test Whether it's in test mode or not.
* @return string The new subdomain
*/
@cameronjonesweb
cameronjonesweb / functions.php
Last active Dec 8, 2018
Add back the WYSIWYG content editor to the WordPress blog page and display the content on the front end
View functions.php
<?php
/**
* Add the WYSIWYG editor back to the blog page
*
* @param WP_Post $post The post object
*/
function cameronjonesweb_fix_no_editor_on_blog_page( $post ) {
if( $post->ID === get_option( 'page_for_posts' ) ) {
add_post_type_support( 'page', 'editor' );
}
@cameronjonesweb
cameronjonesweb / add-script-handle.php
Created Apr 5, 2018
Add the script handle to enqueued script tags
View add-script-handle.php
<?php
add_filter( 'script_loader_tag', 'cameronjonesweb_add_script_handle', 10, 3 );
function cameronjonesweb_add_script_handle( $tag, $handle, $src ) {
return str_replace( '<script', sprintf(
'<script data-handle="%1$s"',
esc_attr( $handle )
), $tag );
}
View new-wp-query.php
<?php
/**
* A custom WP_Query object that will always be empty
*/
$query = new WP_Query( array(
'post__in' => array( 0 )
) );
View mark-notifications-read.php
<?php
function cameronjonesweb_bp_mark_notifications_read() {
// Get the action.
$action = !empty( $_GET['action'] ) ? $_GET['action'] : '';
$nonce = !empty( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : '';
$id = !empty( $_GET['notification_id'] ) ? $_GET['notification_id'] : '';
// Bail if no action or no ID.
@cameronjonesweb
cameronjonesweb / cameronjonesweb-google-fonts.php
Last active Sep 16, 2017
[PHP] Helper function for retrieving Google Fonts stylesheet URLs
View cameronjonesweb-google-fonts.php
<?php
/**
* Generates a URL for getting a Google Font stylesheet URL
*
* @copyright 2017 Cameron Jones
* @license MIT
* @param array $args
* @return string URL of the Google Font family
*/
function cameronjonesweb_google_fonts( $args ) {
View htaccess.txt
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
View cameronjonesweb-facebook-page-slug.php
<?php
function cameronjonesweb_facebook_page_slug( $url ) {
$slug = str_replace(
array(
'https://facebook.com/', 'https://www.facebook.com/', 'http://facebook.com/', 'http://www.facebook.com/'
),
'',
rtrim(
You can’t perform that action at this time.