Functions - Source Excerpt 01
Summary
This source excerpt preserves a bounded section of Antichrist.net/wp-content/themes/antichrist-net/functions.php so readers can inspect the evidence without opening the full source file.
**Source path:** Antichrist.net/wp-content/themes/antichrist-net/functions.php
<?php
/**
* Antichrist.net theme functions.
*
* @package AntichristNet
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'ACN_THEME_VERSION' ) ) {
define( 'ACN_THEME_VERSION', '3.28.0' );
}
/**
* Theme setup.
*/
function acn_theme_setup() {
load_theme_textdomain( 'antichrist-net', get_template_directory() . '/languages' );
add_theme_support( 'title-tag' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'wp-block-styles' );
add_theme_support( 'align-wide' );
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script', 'navigation-widgets' ) );
add_theme_support(
'custom-logo',
array(
'height' => 154,
'width' => 906,
'flex-height' => true,
'flex-width' => true,
)
);
register_nav_menus(
array(
'primary' => esc_html__( 'Primary Menu', 'antichrist-net' ),
'footer' => esc_html__( 'Footer Menu', 'antichrist-net' ),
)
);
add_image_size( 'acn-card', 720, 480, true );
add_image_size( 'acn-hero', 1800, 900, true );
}
add_action( 'after_setup_theme', 'acn_theme_setup' );
/**
* Content width.
*/
function acn_content_width() {
$GLOBALS['content_width'] = apply_filters( 'acn_content_width', 880 );
}
add_action( 'after_setup_theme', 'acn_content_width', 0 );
/**
* Enqueue theme assets.
*/
function acn_enqueue_assets() {
wp_enqueue_style( 'acn-main', get_template_directory_uri() . '/assets/css/main.css', array(), ACN_THEME_VERSION );
wp_enqueue_script( 'acn-main', get_template_directory_uri() . '/assets/js/main.js', array(), ACN_THEME_VERSION, true );
}
add_action( 'wp_enqueue_scripts', 'acn_enqueue_assets' );
/**
* Remove default WordPress front-end assets that are not used by the theme shell.
*/
function acn_trim_frontend_overhead() {
if ( is_admin() ) {
return;
}
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
remove_action( 'wp_footer', 'wp_oembed_add_host_js' );
}
add_action( 'init', 'acn_trim_frontend_overhead' );
/**
* Dequeue block editor styles on the classic front end unless a child integration keeps them.
*/
function acn_dequeue_unused_frontend_assets() {
if ( is_admin() ) {
return;
}
if ( ! apply_filters( 'acn_keep_core_block_styles', false ) ) {
foreach ( array( 'wp-block-library', 'wp-block-library-theme', 'global-styles', 'classic-theme-styles', 'wc-blocks-style' ) as $style_handle ) {
wp_dequeue_style( $style_handle );
wp_deregister_style( $style_handle );
}
}
wp_deregister_script( 'wp-embed' );
if ( ! is_user_logged_in() ) {
wp_deregister_style( 'dashicons' );
}
}
add_action( 'wp_enqueue_scripts', 'acn_dequeue_unused_frontend_assets', 100 );
/**
* Normalize the current front-end request path for public home detection.
*
* @return string
*/
function acn_current_public_request_path() {
$path = isset( $_SERVER['REQUEST_URI'] ) ? (string) wp_parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ) : '/';
if ( ! is_string( $path ) || '' === $path ) {
$path = '/';
}
$path = '/' . ltrim( str_replace( '\\', '/', $path ), '/' );
$path = preg_replace( '#/+#', '/', $path );
$home_path = wp_parse_url( (string) get_option( 'home' ), PHP_URL_PATH );
$home_path = is_string( $home_path ) ? '/' . trim( $home_path, '/' ) : '/';
$home_path = '/' === $home_path ? '/' : untrailingslashit( $home_path );
if ( '/' !== $home_path ) {
if ( $path === $home_path ) {
$path = '/';
} elseif ( 0 === strpos( $path, $home_path . '/' ) ) {
$path = substr( $path, strlen( $home_path ) );
$path = '' === $path ? '/' : $path;
}
}
if ( '/index.php' === untrailingslashit( $path ) ) {
$path = '/';
}
return trailingslashit( $path );
}
/**
* Locale URL tags that may appear as a localized home path.
*
* @return array
*/
function acn_public_home_locale_tags() {
$tags = array( 'en-us', 'es-us' );
foreach ( array( '\UAIXLocaleRouter\LocaleRepository', '\Ns12LocaleRouter\LocaleRepository' ) as $repository_class ) {
if ( ! class_exists( $repository_class ) || ! method_exists( $repository_class, 'get_enabled_locales' ) ) {
continue;
}
foreach ( $repository_class::get_enabled_locales() as $locale ) {
if ( ! empty( $locale['urlTag'] ) ) {
$tags[] = strtolower( trim( (string) $locale['urlTag'], '/' ) );
}
}
}
return array_values( array_unique( array_filter( $tags ) ) );
}
/**
* Detect the public home route even when locale routing or reading settings
* leave WordPress thinking the request is the posts index.
*
* @return bool
*/
function acn_is_public_home_request() {
if ( is_admin() || wp_doing_ajax() || wp_doing_cron() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
return false;
}
$path = acn_current_public_request_path();
if ( '/' === $path ) {
return true;
}
$segments = array_values( array_filter( explode( '/', trim( $path, '/' ) ), 'strlen' ) );
return 1 === count( $segments ) && in_array( strtolower( $segments[0] ), acn_public_home_locale_tags(), true );
}
/**
* Keep the public home URLs on the front-page template.
*
* @param string $template Template path chosen by WordPress.
* @return string
*/
function acn_force_public_home_template( $template ) {
if ( ! acn_is_public_home_request() ) {
return $template;
}
$front_page_template = locate_template( 'front-page.php' );
return $front_page_template ? $front_page_template : $template;
}
add_filter( 'template_include', 'acn_force_public_home_template', 99 );
/**
* Keep public home SEO titles aligned with the forced front page template.
*
* @param string $title Document title.
* @return string
*/
function acn_public_home_document_title( $title ) {
if ( ! acn_is_public_home_request() ) {
return $title;
}
return (string) get_bloginfo( 'name' );
}
add_filter( 'pre_get_document_title', 'acn_public_home_document_title', 30 );
/**
* Provide the same title to UAIX Locale Router metadata when it is active.
*
* @param string $title Existing localized SEO title.
* @return string
*/
function acn_public_home_uaix_title( $title ) {
if ( ! acn_is_public_home_request() ) {
return $title;
}
return (string) get_bloginfo( 'name' );
}
add_filter( 'uaixlr_seo_title', 'acn_public_home_uaix_title', 30 );
/**
* Prioritize the above-the-fold seal image on the home page.
*/
function acn_preload_front_page_assets() {
if ( ! is_front_page() && ! acn_is_public_home_request() ) {
return;
}
printf(
'<link rel="preload" as="image" href="%s" fetchpriority="high">' . "\n",
esc_url( get_template_directory_uri() . '/assets/img/foundation-seal-512.png' )
);
}
add_action( 'wp_head', 'acn_preload_front_page_assets', 5 );
/**
* Default public description used when a page has no excerpt.
*
* @return string
*/
function acn_seo_default_description() {
return __( 'Antichrist.net is a research archive for Antichrist traditions, apocalyptic politics, religious nationalism, AI prophecy culture, surveillance, symbolic systems, and nonviolent civic analysis.', 'antichrist-net' );
}
/**
* Collapse a text source into a search/social friendly description.
*
* @param string $text Raw text.
* @return string
*/
function acn_seo_clean_description( $text ) {
$text = html_entity_decode( wp_strip_all_tags( strip_shortcodes( (string) $text ) ), ENT_QUOTES, get_bloginfo( 'charset' ) );
$text = preg_replace( '/\s+/', ' ', trim( $text ) );
if ( '' === $text ) {
return acn_seo_default_description();
}
if ( function_exists( 'mb_strlen' ) && function_exists( 'mb_substr' ) ) {
if ( mb_strlen( $text ) > 158 ) {
return rtrim( mb_substr( $text, 0, 155 ), " \t\n\r\0\x0B.,;:" ) . '...';
}
return $text;
}
if ( strlen( $text ) > 158 ) {
return rtrim( substr( $text, 0, 155 ), " \t\n\r\0\x0B.,;:" ) . '...';
}
return $text;
}
/**
* Build the current page description.
*
* @return string
*/
function acn_seo_description() {
if ( is_front_page() || is_home() ) {
return acn_seo_default_description();
}
if ( is_singular() ) {
$post = get_queried_object();
if ( $post instanceof WP_Post ) {
$source = has_excerpt( $post ) ? get_the_excerpt( $post ) : $post->post_content;
return acn_seo_clean_description( $source );
}
}
if ( is_search() ) {
return acn_seo_clean_description( sprintf( __( 'Search results for "%s" on Antichrist.net.', 'antichrist-net' ), get_search_query() ) );
}
if ( is_archive() ) {
$description = get_the_archive_description();
if ( $description ) {
return acn_seo_clean_description( $description );
}
return acn_seo_clean_description( get_the_archive_title() );
}
return acn_seo_default_description();
}