Skip to content

Instantly share code, notes, and snippets.

@danielpost
Last active October 22, 2018 12:12
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 danielpost/97b9346a4388be83fdd7d8fdd550d4d3 to your computer and use it in GitHub Desktop.
Save danielpost/97b9346a4388be83fdd7d8fdd550d4d3 to your computer and use it in GitHub Desktop.
WordPress theme setup
<?php
namespace Bahama;
class Core {
public function setup() {
add_action('after_setup_theme', [$this, 'i18n']);
add_action('after_setup_theme', [$this, 'theme_setup']);
add_action('wp_enqueue_scripts', [$this, 'scripts']);
add_action('wp_enqueue_scripts', [$this, 'styles']);
}
public function i18n() {
load_theme_textdomain('bahama', BAHAMA_PATH . '/languages');
}
public function theme_setup() {
add_theme_support('automatic-feed-links');
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_theme_support('html5', ['search-form', 'gallery']);
register_nav_menus(
[
'primary' => esc_html__('Primary Menu', 'bahama'),
]
);
}
public function scripts() {
wp_enqueue_script(
'bahama-app',
BAHAMA_TEMPLATE_URL . 'assets/js/app.js',
[],
BAHAMA_VERSION,
true
);
}
public function styles() {
wp_enqueue_style(
'bahama-stylesheet',
get_stylesheet_uri(),
[],
BAHAMA_VERSION
);
}
}
<?php
define('BAHAMA_VERSION', '0.1.0');
define('BAHAMA_TEMPLATE_URL', get_template_directory_uri());
define('BAHAMA_PATH', get_template_directory() . '/');
define('BAHAMA_INC', BAHAMA_PATH . 'includes/');
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once 'vendor/autoload.php';
$core = new Bahama\Core;
$core->setup();
}
<?php
namespace Bahama;
class Helpers
{
public function get_body_class() {
echo 'test';
}
}
<?php
get_header(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php Bahama\Helpers::get_body_class(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php
get_footer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment