Functions - Source Excerpt 03
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
echo '<meta name="description" content="' . esc_attr( $description ) . "\" />\n";
if ( $robots ) {
echo '<meta name="robots" content="' . esc_attr( $robots ) . "\" />\n";
}
echo '<link rel="canonical" href="' . esc_url( $url ) . "\" />\n";
echo '<meta name="theme-color" content="#050505" />' . "\n";
echo '<meta property="og:type" content="' . esc_attr( $og_type ) . "\" />\n";
echo '<meta property="og:site_name" content="' . esc_attr( get_bloginfo( 'name' ) ) . "\" />\n";
echo '<meta property="og:title" content="' . esc_attr( $title ) . "\" />\n";
echo '<meta property="og:description" content="' . esc_attr( $description ) . "\" />\n";
echo '<meta property="og:url" content="' . esc_url( $url ) . "\" />\n";
echo '<meta property="og:locale" content="' . esc_attr( $og_locale ) . "\" />\n";
echo '<meta property="og:locale:alternate" content="' . esc_attr( 'en_US' === $og_locale ? 'es_US' : 'en_US' ) . "\" />\n";
echo '<meta property="og:image" content="' . esc_url( $image['url'] ) . "\" />\n";
if ( ! empty( $image['width'] ) && ! empty( $image['height'] ) ) {
echo '<meta property="og:image:width" content="' . absint( $image['width'] ) . "\" />\n";
echo '<meta property="og:image:height" content="' . absint( $image['height'] ) . "\" />\n";
}
echo '<meta name="twitter:card" content="summary_large_image" />' . "\n";
echo '<meta name="twitter:title" content="' . esc_attr( $title ) . "\" />\n";
echo '<meta name="twitter:description" content="' . esc_attr( $description ) . "\" />\n";
echo '<meta name="twitter:image" content="' . esc_url( $image['url'] ) . "\" />\n";
if ( is_singular() ) {
$post = get_queried_object();
if ( $post instanceof WP_Post ) {
echo '<meta property="article:published_time" content="' . esc_attr( get_the_date( DATE_W3C, $post ) ) . "\" />\n";
echo '<meta property="article:modified_time" content="' . esc_attr( get_the_modified_date( DATE_W3C, $post ) ) . "\" />\n";
}
}
echo '<script type="application/ld+json">' . wp_json_encode( acn_seo_schema( $title, $description, $url, $image ), JSON_UNESCAPED_SLASHES ) . "</script>\n";
}
add_action( 'wp_head', 'acn_render_seo_metadata', 2 );
/**
* Add editor styles.
*/
function acn_add_editor_styles() {
add_editor_style( 'assets/css/main.css' );
}
add_action( 'admin_init', 'acn_add_editor_styles' );
/**
* Register sidebars.
*/
function acn_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Footer Column One', 'antichrist-net' ),
'id' => 'footer-1',
'description' => esc_html__( 'Footer widget area.', 'antichrist-net' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Footer Column Two', 'antichrist-net' ),
'id' => 'footer-2',
'description' => esc_html__( 'Footer widget area.', 'antichrist-net' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'acn_widgets_init' );
/**
* Theme customizer.
*
* @param WP_Customize_Manager $wp_customize Customizer object.
*/
function acn_customize_register( $wp_customize ) {
$wp_customize->add_section(
'acn_editorial',
array(
'title' => esc_html__( 'Antichrist.net Editorial', 'antichrist-net' ),
'description' => esc_html__( 'Site framing, footer notice, and default calls to action.', 'antichrist-net' ),
'priority' => 35,
)
);
$wp_customize->add_setting(
'acn_site_notice',
array(
'default' => esc_html__( 'Antichrist.net is an archive, analysis, and community research platform. It does not endorse harassment, hatred, or violence.', 'antichrist-net' ),
'sanitize_callback' => 'sanitize_text_field',
)
);
$wp_customize->add_control(
'acn_site_notice',
array(
'label' => esc_html__( 'Footer notice', 'antichrist-net' ),
'section' => 'acn_editorial',
'type' => 'text',
)
);
}
add_action( 'customize_register', 'acn_customize_register' );
/**
* Fallback logo markup.
*/
function acn_site_logo() {
if ( has_custom_logo() ) {
the_custom_logo();
return;
}
$logo_url = get_template_directory_uri() . '/assets/img/wwwAntiChristNet-Original.gif';
printf(
'<a class="site-logo fallback-logo" href="%1$s" rel="home"><img src="%2$s" alt="%3$s" width="906" height="154" /></a>',
esc_url( home_url( '/' ) ),
esc_url( $logo_url ),
esc_attr( get_bloginfo( 'name' ) )
);
}
/**
* Return the current locale URL tag for front-end link generation.
*
* @return string
*/
function acn_current_locale_url_tag() {
foreach ( array( '\UAIXLocaleRouter\Router', '\Ns12LocaleRouter\Router' ) as $router_class ) {
if ( class_exists( $router_class ) ) {
$current = $router_class::get_current_url_tag();
if ( is_string( $current ) && '' !== $current ) {
return $current;
}
}
}
$request_path = isset( $_SERVER['REQUEST_URI'] ) ? (string) wp_parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ) : '';
$first_segment = strtok( trim( $request_path, '/' ), '/' );
if ( ! is_string( $first_segment ) || '' === $first_segment ) {
return '';
}
foreach ( array( '\UAIXLocaleRouter\LocaleRepository', '\Ns12LocaleRouter\LocaleRepository' ) as $locale_repository ) {
if ( class_exists( $locale_repository ) ) {
$tag = $locale_repository::normalize_url_tag( $first_segment );
if ( method_exists( $locale_repository, 'canonical_enabled_url_tag_for_segment' ) ) {
$tag = $locale_repository::canonical_enabled_url_tag_for_segment( $tag );
return is_string( $tag ) ? $tag : '';
}
if ( method_exists( $locale_repository, 'is_enabled_url_tag' ) && $locale_repository::is_enabled_url_tag( $tag ) ) {
return $tag;
}
}
}
$first_segment = strtolower( $first_segment );
return in_array( $first_segment, array( 'en-us', 'es-us' ), true ) ? $first_segment : '';
}
/**
* Apply the active locale prefix to an internal URL.
*
* @param string $url URL.
* @return string
*/
function acn_localized_url( $url ) {
$url = (string) $url;
$tag = acn_current_locale_url_tag();
$path_class = '';
if ( class_exists( '\UAIXLocaleRouter\Support\Path' ) ) {
$path_class = '\UAIXLocaleRouter\Support\Path';
} elseif ( class_exists( '\Ns12LocaleRouter\Support\Path' ) ) {
$path_class = '\Ns12LocaleRouter\Support\Path';
}
if ( '' === $tag || '' === $path_class ) {
return $url;
}
$parts = wp_parse_url( $url );
if ( ! is_array( $parts ) ) {
return $url;
}
$home_host = strtolower( (string) wp_parse_url( home_url( '/' ), PHP_URL_HOST ) );
$url_host = strtolower( (string) ( $parts['host'] ?? $home_host ) );
if ( '' !== $home_host && '' !== $url_host && $home_host !== $url_host ) {
return $url;
}
$path = isset( $parts['path'] ) ? (string) $parts['path'] : '/';
$query = array();
if ( ! empty( $parts['query'] ) ) {
parse_str( (string) $parts['query'], $query );
if ( ! is_array( $query ) ) {
$query = array();
}
}
return $path_class::build_front_url(
$path_class::localize_path( $path, $tag ),
$query,
isset( $parts['fragment'] ) ? (string) $parts['fragment'] : ''
);
}
/**
* Return permalink by slug, with fallback.
*
* @param string $slug Slug.
* @return string
*/
function acn_page_url( $slug ) {
if ( '' === trim( (string) $slug, '/' ) ) {
return acn_localized_url( home_url( '/' ) );
}
$page = get_page_by_path( $slug );
if ( $page instanceof WP_Post ) {
return acn_localized_url( get_permalink( $page ) );
}
return acn_localized_url( home_url( '/' . trim( $slug, '/' ) . '/' ) );
}
/**
* Normalize a URL path for header navigation comparisons.
*
* @param string $url URL.
* @return string
*/
function acn_navigation_path_key( $url ) {
$url = trim( (string) $url );
if ( '' === $url || '#' === $url ) {
return '';
}
$parts = wp_parse_url( $url );
if ( ! is_array( $parts ) ) {
return '';
}
$home_host = strtolower( (string) wp_parse_url( home_url( '/' ), PHP_URL_HOST ) );
$url_host = strtolower( (string) ( $parts['host'] ?? $home_host ) );
if ( '' !== $home_host && '' !== $url_host && $home_host !== $url_host ) {
return 'external:' . md5( $url );
}
$path = isset( $parts['path'] ) ? (string) $parts['path'] : '/';
$path = '/' . trim( 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 ) );
}
}