Skip to content

Instantly share code, notes, and snippets.

@icreatesolutions
Created September 19, 2018 05:08
Show Gist options
  • Save icreatesolutions/a5ce3ee7289dd1beb5d727923b46e878 to your computer and use it in GitHub Desktop.
Save icreatesolutions/a5ce3ee7289dd1beb5d727923b46e878 to your computer and use it in GitHub Desktop.
Simple Endpoint Plugin
<?php
/*
Plugin Name: iCreate Simple Endpoint
Description: Simple way to add a landing page endpoint
Author: iCreate Advertising
Version: 1.0.0
Author URI: https://icreateadvertising.com.au
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// CONFIG LANDING PAGE ENDPOINT
//remember to flush rewrite rules if you change the endpoint
define( 'IC_LANDING_ENDPOINT', 'lp' );
// END CONFIG
add_action( 'init', 'ic_ep_endpoint' );
add_filter( 'body_class', 'ic_ep_body_class' );
register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
register_activation_hook( __FILE__, 'ic_ep_flush_rewrites' );
function ic_ep_flush_rewrites() {
ic_ep_endpoint();
flush_rewrite_rules();
}
function ic_ep_endpoint() {
add_rewrite_endpoint( IC_LANDING_ENDPOINT, EP_ALL );
}
function ic_ep_body_class( $classes ) {
if ( ic_is_landing() ) {
$classes[] = 'landing-page';
}
return $classes;
}
function ic_is_landing() {
global $wp_query;
return isset( $wp_query->query_vars[ IC_LANDING_ENDPOINT ] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment