Skip to content
wiki.fftac.org

Antichrist Resource Pages - Source Excerpt 09

Back to Antichrist Resource Pages

Summary

This source excerpt preserves a bounded section of FFTAC/wp-content/themes/fftac-who-we-are/inc/antichrist-resource-pages.php so readers can inspect the evidence without opening the full source file.

**Source path:** FFTAC/wp-content/themes/fftac-who-we-are/inc/antichrist-resource-pages.php

/**
 * Use the resource template for resource routes.
 *
 * @param string $template Template path.
 * @return string
 */
function fftac_resource_template_include( $template ) {
	$slug = fftac_resource_slug();

	if ( '' !== $slug && 'sitemap' !== $slug && fftac_resource_page( $slug ) ) {
		return get_template_directory() . '/antichrist-resource.php';
	}

	return $template;
}
add_filter( 'template_include', 'fftac_resource_template_include' );

/**
 * Improve document title for resource routes.
 *
 * @param array<string,string> $parts Title parts.
 * @return array<string,string>
 */
function fftac_resource_document_title_parts( $parts ) {
	$page = fftac_resource_page( fftac_resource_slug() );

	if ( $page ) {
		$parts['title'] = $page['title'];
	}

	return $parts;
}
add_filter( 'document_title_parts', 'fftac_resource_document_title_parts' );

/**
 * Add SEO and social metadata for resource routes.
 */
function fftac_resource_meta_tags() {
	$slug = fftac_resource_slug();
	$page = fftac_resource_page( $slug );

	if ( ! $page ) {
		return;
	}

	$url         = fftac_resource_url( $page['slug'] );
	$title       = $page['title'] . ' - ' . get_bloginfo( 'name' );
	$description = isset( $page['description'] ) ? $page['description'] : '';
	$type        = 'hub' === $page['slug'] ? 'CollectionPage' : 'WebPage';
	$schema      = array(
		'@context'    => 'https://schema.org',
		'@type'       => $type,
		'name'        => $page['title'],
		'description' => $description,
		'url'         => $url,
		'dateModified' => isset( $page['updated'] ) ? $page['updated'] : '',
		'isPartOf'    => array(
			'@type' => 'WebSite',
			'name'  => get_bloginfo( 'name' ),
			'url'   => home_url( '/' ),
		),
		'breadcrumb'  => array(
			'@type'           => 'BreadcrumbList',
			'itemListElement' => array(
				array(
					'@type'    => 'ListItem',
					'position' => 1,
					'name'     => get_bloginfo( 'name' ),
					'item'     => home_url( '/' ),
				),
				array(
					'@type'    => 'ListItem',
					'position' => 2,
					'name'     => 'Antichrist Resource Hub',
					'item'     => fftac_resource_url( 'hub' ),
				),
			),
		),
	);

	if ( 'hub' !== $page['slug'] ) {
		$schema['breadcrumb']['itemListElement'][] = array(
			'@type'    => 'ListItem',
			'position' => 3,
			'name'     => $page['title'],
			'item'     => $url,
		);
	}

	printf( "\n" . '<meta name="description" content="%s">' . "\n", esc_attr( $description ) );
	printf( '<link rel="canonical" href="%s">' . "\n", esc_url( $url ) );
	printf( '<meta property="og:type" content="article">' . "\n" );
	printf( '<meta property="og:title" content="%s">' . "\n", esc_attr( $title ) );
	printf( '<meta property="og:description" content="%s">' . "\n", esc_attr( $description ) );
	printf( '<meta property="og:url" content="%s">' . "\n", esc_url( $url ) );
	printf( '<meta name="twitter:card" content="summary">' . "\n" );
	printf( '<meta name="twitter:title" content="%s">' . "\n", esc_attr( $title ) );
	printf( '<meta name="twitter:description" content="%s">' . "\n", esc_attr( $description ) );
	printf( '<script type="application/ld+json">%s</script>' . "\n", wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) );
}
add_action( 'wp_head', 'fftac_resource_meta_tags', 4 );

/**
 * Add route-specific body classes.
 *
 * @param array<int,string> $classes Body classes.
 * @return array<int,string>
 */
function fftac_resource_body_classes( $classes ) {
	$slug = fftac_resource_slug();

	if ( '' !== $slug && 'sitemap' !== $slug && fftac_resource_page( $slug ) ) {
		$classes[] = 'fftac-resource-page';
		$classes[] = 'fftac-resource-' . sanitize_html_class( $slug );
	}

	return $classes;
}
add_filter( 'body_class', 'fftac_resource_body_classes' );

/**
 * Output XML sitemap for the resource library.
 */
function fftac_resource_output_sitemap() {
	status_header( 200 );
	nocache_headers();
	header( 'Content-Type: application/xml; charset=' . get_option( 'blog_charset' ) );

	echo '<?xml version="1.0" encoding="' . esc_attr( get_option( 'blog_charset' ) ) . '"?>' . "\n";
	echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";

	foreach ( fftac_resource_pages() as $page ) {
		echo "\t<url>\n";
		echo "\t\t<loc>" . esc_url( fftac_resource_url( $page['slug'] ) ) . "</loc>\n";
		echo "\t\t<lastmod>" . esc_html( isset( $page['updated'] ) ? $page['updated'] : gmdate( 'Y-m-d' ) ) . "</lastmod>\n";
		echo "\t\t<changefreq>monthly</changefreq>\n";
		echo "\t\t<priority>" . ( 'hub' === $page['slug'] ? '1.0' : '0.8' ) . "</priority>\n";
		echo "\t</url>\n";
	}

	echo '</urlset>';
}