Skip to content

Instantly share code, notes, and snippets.

View jcamp's full-sized avatar

Jonathan jcamp

View GitHub Profile
@jcamp
jcamp / nav_goback.js
Created August 15, 2018 14:07
Simulate a goback link for navigation (jQuery)
$(document).ready(function(){
$('a.back').click(function(){
parent.history.back();
return false;
});
});
@jcamp
jcamp / write_log.php
Created August 13, 2018 16:45
Very simple logging to a file by calling 'write_log' in our php code (wordpress edition)
<?php
// Taken pretty much from https://www.elegantthemes.com/blog/tips-tricks/using-the-wordpress-debug-log
// error_log info on php site - http://php.net/manual/en/function.error-log.php
// Just stick this function in your functions.php if you like :)
if ( ! function_exists('write_log')) {
function write_log ( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
// error_log - Sends an error message to the web server's error log or to a file.
error_log( print_r( $log, true ) );
@jcamp
jcamp / functions_enqueue_child_theme.php
Created August 13, 2018 16:40
Wordpress enqueue styles with child styles (takes into account Bootstrap in this case load bootstrap and then override)
<?php
// Basically we need to make sure we load ALL our stylesheets for our child theme AFTER bootstrap
// that way we can override bootstrap without using crappy !important overrides, etc.
// This sample uses the transportex theme but just replace that for your own theme.
function my_theme_enqueue_styles() {
$parent_style = 'transportex-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
@jcamp
jcamp / show_hide_cookie_law.html
Created August 3, 2018 10:28
Show and hide cookie law using cookies
@jcamp
jcamp / ajax_form_submit.js
Last active August 3, 2018 10:24
Use Ajax to check form fields and submit
var isHttps = location.protocol.match(/https/);
var http = isHttps ? 'https://' : 'http://';
var site_url = http + location.host + '/yoursite';
$(function(){
$('#form-btn').on('click',function(event){
var email_test = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var form_name = $('#form-name').val();
var form_email = $('#form-email').val();
@jcamp
jcamp / http_or_not.js
Created August 3, 2018 10:18
Check and set js variable if running http or https
var isHttps = location.protocol.match(/https/);
var http = isHttps ? 'https://' : 'http://';
var site_url = http + location.host + '/webpage';
@jcamp
jcamp / limittext.php
Created July 25, 2018 14:41
PHP function - Truncate string to a number of words and add elipse for read more...
<?php
function limit_text($text, $limit) {
if (str_word_count($text, 0) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . '...';
}
return $text;
}
@jcamp
jcamp / add_custom_types.php
Created July 7, 2018 10:47 — forked from barbwiredmedia/add_custom_types.php
Wordpress_Make Archives.php Include Custom Post Types - Archives.php only shows content of type 'post', but you can alter it to include custom post types. http://css-tricks.com/snippets/wordpress/make-archives-php-include-custom-post-types/
//functions.php
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'your-custom-post-type-here'
));
return $query;
}
}
@jcamp
jcamp / wp-config.php
Created July 7, 2018 10:45 — forked from barbwiredmedia/wp-config.php
Wordpress wp-config . Define Site URL and home when migrating to new URL or server, revisions count, SSL Force
//Define site URLS
define('WP_SITEURL', 'http://www.yoursite.net');
define('WP_HOME', 'http://www.yoursite.net');
//Change revision limits to keep database from overflowing
define( 'WP_POST_REVISIONS', 5 );
//Change to force SSL
define( 'FORCE_SSL_LOGIN', false );
<script src="jquery.js"></script>
<script src="modernizr.js"></script>
<script>
$(document).ready(function(){
if(!Modernizr.input.placeholder){
$('[placeholder]').focus(function() {
var input = $(this);