init
This commit is contained in:
110
theme/inc/enqueue.php
Normal file
110
theme/inc/enqueue.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* Asset Enqueuing — frontend styles, scripts, and editor additions.
|
||||
*
|
||||
* @package OTS_Theme
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* ── Frontend assets ───────────────────────────────────────── */
|
||||
add_action( 'wp_enqueue_scripts', function () {
|
||||
|
||||
// Main stylesheet (supplements theme.json generated styles)
|
||||
wp_enqueue_style(
|
||||
'oribi-main',
|
||||
ORIBI_URI . '/assets/css/main.css',
|
||||
[],
|
||||
ORIBI_VERSION
|
||||
);
|
||||
|
||||
// Main JS — dark mode, sticky header, mobile nav, scroll animations
|
||||
wp_enqueue_script(
|
||||
'oribi-main',
|
||||
ORIBI_URI . '/assets/js/main.js',
|
||||
[],
|
||||
ORIBI_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
// Localize AJAX endpoint for the contact form
|
||||
wp_localize_script( 'oribi-main', 'oribiAjax', [
|
||||
'url' => admin_url( 'admin-ajax.php' ),
|
||||
'nonce' => wp_create_nonce( 'oribi_contact_nonce' ),
|
||||
] );
|
||||
|
||||
// Threaded comments (if ever enabled)
|
||||
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
|
||||
wp_enqueue_script( 'comment-reply' );
|
||||
}
|
||||
} );
|
||||
|
||||
/* ── Font Awesome 6 Free (CDN) ─────────────────────────────── */
|
||||
add_action( 'wp_enqueue_scripts', function () {
|
||||
wp_enqueue_style(
|
||||
'font-awesome',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css',
|
||||
[],
|
||||
null
|
||||
);
|
||||
} );
|
||||
|
||||
add_action( 'enqueue_block_editor_assets', function () {
|
||||
wp_enqueue_style(
|
||||
'font-awesome',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css',
|
||||
[],
|
||||
null
|
||||
);
|
||||
} );
|
||||
|
||||
/* ── Google Fonts — dynamic based on theme settings ────────── */
|
||||
add_action( 'wp_enqueue_scripts', 'oribi_enqueue_selected_fonts' );
|
||||
add_action( 'enqueue_block_editor_assets', 'oribi_enqueue_selected_fonts' );
|
||||
|
||||
/**
|
||||
* Enqueue Google Fonts stylesheets for the selected body & heading fonts.
|
||||
*/
|
||||
function oribi_enqueue_selected_fonts() {
|
||||
if ( ! function_exists( 'oribi_get_setting' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$slugs = array_unique( array_filter( [
|
||||
oribi_get_setting( 'font_family' ),
|
||||
oribi_get_setting( 'font_heading' ),
|
||||
] ) );
|
||||
|
||||
foreach ( $slugs as $slug ) {
|
||||
$url = oribi_get_google_font_url( $slug );
|
||||
if ( $url ) {
|
||||
wp_enqueue_style(
|
||||
'oribi-gf-' . $slug,
|
||||
$url,
|
||||
[],
|
||||
null
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Generated theme CSS (colour / font / spacing overrides) ─ */
|
||||
add_action( 'wp_enqueue_scripts', 'oribi_enqueue_generated_css', 20 );
|
||||
add_action( 'enqueue_block_editor_assets', 'oribi_enqueue_generated_css', 20 );
|
||||
|
||||
/**
|
||||
* Enqueue the dynamically generated CSS file that applies design-token
|
||||
* overrides from the admin settings page.
|
||||
*/
|
||||
function oribi_enqueue_generated_css() {
|
||||
if ( ! function_exists( 'oribi_generated_css_url' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url = oribi_generated_css_url();
|
||||
$ver = get_theme_mod( 'oribi_css_version', '1' );
|
||||
|
||||
wp_enqueue_style( 'oribi-custom-tokens', $url, [ 'oribi-main' ], $ver );
|
||||
}
|
||||
Reference in New Issue
Block a user