Skip to content

Instantly share code, notes, and snippets.

View jimfloss's full-sized avatar

Jim Floss jimfloss

View GitHub Profile
@jimfloss
jimfloss / nav
Created January 19, 2018 02:17
WordPress Basic Navigation Code
<header id="masthead" class="site-header header-*">
<div class="container">
<div class="row">
<div id="site-logo" class="col-4">
<h1><a href="#" rel="home"><img src="logo.png" srcset="logo1x.png 1x, logo2x.png 2x, logo3x.png 3x, logo4x.png 4x" alt="Logo"></a></h1>
</div>
<!-- #site-logo -->
<nav id="site-navigation" class="main-navigation col-8" itemscope="itemscope" itemtype="http://www.schema.org/SiteNavigationElement">
@jimfloss
jimfloss / WPCustomWYSIWYGeditor.php
Last active March 2, 2022 03:59
Custom WYSIWYG editor
<?php
function add_custom_meta_boxes_to_page() {
add_meta_box( 'custom_wysiwyg', __('Custom WYSIWYG'), 'custom_wysiwyg', 'page', 'normal', 'high' );
}
add_action( 'add_meta_boxes_page', 'add_custom_meta_boxes_to_page' );
add_action( 'save_post', 'save_custom_wysiwyg' );
//Build
function custom_wysiwyg() {
global $post;
@jimfloss
jimfloss / WPMetaboxByPost.php
Last active January 30, 2018 17:41
Add custom meta boxes to specific post or page
<?php
function add_custom_meta_boxes_to_page() {
global $post;
if ( 'product-configurator' == $post->post_name ) {
remove_post_type_support('page', 'editor');
add_meta_box( 'description_of_configurator', __('Configurator Information'), 'description_of_configurator', 'page', 'normal', 'high' );
add_meta_box( 'hero_content', __('Hero Content'), 'hero_content', 'page', 'side', 'low' );
}
}
add_action( 'add_meta_boxes_page', 'add_custom_meta_boxes_to_page' );
@jimfloss
jimfloss / WPForceTemplate.php
Last active January 30, 2018 17:41
Force Template
<?php
function custom_page_template( $page_template ){
if ( is_page( 'product-configurator' ) ) {
$page_template = dirname( __FILE__ ) . '/product_configurator.php';
}
return $page_template;
}
add_filter( 'page_template', 'custom_page_template' );
@jimfloss
jimfloss / AddWPPages.php
Created January 30, 2018 17:40
Programmatically add WP pages or posts
<?php
//Create Page
function create_page() {
if ( !$post = get_page_by_path( 'product-configurator', OBJECT, 'post_type' ) ) {
$user_id = get_current_user_id();
$page = array(
'post_title' => 'Product Configurator',
'post_status' => 'publish',
'post_author' => $user_id,
@jimfloss
jimfloss / ResponsiveVideo.css
Created January 30, 2018 17:56
Responsive Video CSS
.video-wrapper {
position: relative;
width: 100%;
height: 0;
padding-bottom: 56.25%;
margin: 0px auto;
}
.video-wrapper iframe {
position: absolute;
@jimfloss
jimfloss / NewUserEmail.php
Created January 30, 2018 17:57
Programmatically send a New User WooCommerce email
<?php
$woocommerce_customer_new_account_settings = get_option('woocommerce_customer_new_account_settings');
$user_pass = 'generated_password';
$user_login = 'user_name';
$email = 'user_email@email.com';
$blogname = 'user_name';
$password_generated = 'generated_password';
require_once( '/www/wp-content/themes/theme-name/woocommerce/emails/customer-new-account.php' );
$email_content = ob_get_clean();
@jimfloss
jimfloss / ConstantContact.php
Created January 30, 2018 17:58
Add Contact to Constant Contact Using cURL
<?php
//Not original code, just don't want to loose it
// fill in your Constant Contact login and API key
$ccuser = get_theme_mod( 'ccuser' );
$ccpass = get_theme_mod( 'ccpass' );
$cckey = get_theme_mod( 'key' );
// fill in these values
$firstName = "";
$lastName = "";
@jimfloss
jimfloss / ES6 Includes Polyfill
Created April 6, 2018 13:27
Polyfill to make ES6 Includes work in IE 11
//Includes Polyfill
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
'use strict';
if (typeof start !== 'number') {
start = 0;
}
if (start + search.length > this.length) {
return false;
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
//Code here
}