Skip to content

Instantly share code, notes, and snippets.

View jimfloss's full-sized avatar

Jim Floss jimfloss

View GitHub Profile
@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 / 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 / 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 / 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 / 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">