Skip to content

Instantly share code, notes, and snippets.

@kyotoprotokollet
Last active May 14, 2018 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyotoprotokollet/8b6e3f978ce3bd237e359e98cca151f1 to your computer and use it in GitHub Desktop.
Save kyotoprotokollet/8b6e3f978ce3bd237e359e98cca151f1 to your computer and use it in GitHub Desktop.
Landing page plugin boilerplate for Wordpress
<?php
/**
* Plugin Name: Landingpage
* Plugin URI: https://site.com/landingpage
* Description: A landingpage plugin
* Version: 1.0.0
* Author: Author
* Author URI: author.com
* License: GPL2
*/
if ( !is_admin() ) {
add_action('template_redirect','landingpage_2018'); //Fires before determining which template to load.
function landingpage_2018(){
// Enqueue styles and scripts for our plugin. Add class name to body of the template page.
if ( is_page('landingpage') ) {
add_action( 'wp_enqueue_scripts', 'landingpage_enqueued_assets' );
function landingpage_enqueued_assets() {
wp_enqueue_script( 'landingpage_script', plugin_dir_url( __FILE__ ) . 'dist/js/script.min.js', array( 'jquery' ), filemtime(plugin_dir_path( __FILE__ ) . 'dist/js/script.min.js') , true );
wp_enqueue_style( 'landingpage_style', plugin_dir_url( __FILE__ ) . 'dist/css/style.min.css', array(), filemtime(plugin_dir_path( __FILE__ ) . 'dist/css/style.min.css') );
}
add_filter( 'body_class', 'landingpage_class_names' );
function landingpage_class_names( $classes ) {
$classes[] = 'landingpage';
return $classes;
}
}
}
// Set the template for the page
add_filter( 'page_template', 'landingpage_page_template' );
function landingpage_page_template( $page_template ) {
if ( is_page( 'landingpage' ) ) {
$page_template = plugin_dir_path( __FILE__ ). '/landingpage-template.php';
}
return $page_template;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment