Skip to content

Instantly share code, notes, and snippets.

@yanknudtskov
Created April 22, 2016 16:34
Show Gist options
  • Save yanknudtskov/397dbb8ef97b2b45a24bd441b1dfdc6d to your computer and use it in GitHub Desktop.
Save yanknudtskov/397dbb8ef97b2b45a24bd441b1dfdc6d to your computer and use it in GitHub Desktop.
OOP Functions for WordPress functions.php
<?php
class Functions {
private $theme_name;
private $theme_version;
public function __construct( $theme_name, $theme_version ) {
$this->theme_name = $theme_name;
$this->theme_version = $theme_version;
$this->theme_setup();
}
$functions = new Functions( 'my-theme', '1.0.0' );
private function theme_setup() {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}
public function enqueue_styles() {
wp_enqueue_style( $this->theme_name . '_main_css', get_stylesheet_directory_uri() . '/dist/css/main.min.css', array(), $this->theme_version );
wp_enqueue_style( $this->theme_name . '_fontawesome_css', get_stylesheet_directory_uri() . '/bower_components/font-awesome/css/font-awesome.min.css', array(), $this->theme_version );
wp_enqueue_style( $this->theme_name . '_style_css', get_stylesheet_directory_uri() . '/style.css', array($this->theme_name . '_main_css'), $this->theme_version );
}
public function enqueue_scripts() {
wp_enqueue_script( $this->theme_name . '_jquery_js', get_stylesheet_directory_uri() . '/bower_components/jquery/dist/jquery.min.js', array(), $this->theme_version );
wp_enqueue_script( $this->theme_name . '_bootstrap_js', get_stylesheet_directory_uri() . '/bower_components/bootstrap-sass/assets/javascripts/bootstrap.min.js', array(), $this->theme_version );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment