Skip to content

Instantly share code, notes, and snippets.

@kyotoprotokollet kyotoprotokollet/landingpage.php Secret
Last active May 14, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.