Snippets

Joseph Dickson jd-twenty-twenty-three-child

Created by Joseph Dickson last modified
<?php
/**
 * Remove label from archive indexes such as Category or Tag etc.
 * https://developer.wordpress.org/reference/functions/get_the_archive_title/
 */
function jd_twentytwentythree_archive_title( $title ) {
    if ( is_category() ) {
        $title = single_cat_title( '', false );
    } elseif ( is_tag() ) {
        $title = single_tag_title( '', false );
    } elseif ( is_author() ) {
        $title = '<span class="vcard">' . get_the_author() . '</span>';
    } elseif ( is_post_type_archive() ) {
        $title = post_type_archive_title( '', false );
    } elseif ( is_tax() ) {
        $title = single_term_title( '', false );
    }
    return $title;
}
add_filter( 'get_the_archive_title', 'jd_twentytwentythree_archive_title' );


1
2
3
4
5
6
7
<?php
/**
 * Add child theme customizations
 */
include( get_stylesheet_directory( __FILE__ ) . '/inc/archive-title.php' );
include( get_stylesheet_directory( __FILE__ ) . '/inc/opengraph.php' );
include( get_stylesheet_directory( __FILE__ ) . '/inc/post-formats.php' );
<?php
/**
 * Open Graph and Twitter Card Support
 */

function jd_opengraph_meta_tags() {

	if ( has_custom_logo() ) {
		$custom_logo_id = get_theme_mod( 'custom_logo' );
		$image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
		$image = $image[0];
	}

	if (is_home() || is_front_page() ) {
		$description = wp_strip_all_tags( get_bloginfo('description') );
		$permalink = get_home_url();
		$title = wp_strip_all_tags( get_bloginfo('name') );

	} elseif ( is_archive() ) {
		$description = wp_strip_all_tags( term_description() );
		$permalink = get_post_type_archive_link( 'post' );
		$title = wp_strip_all_tags( get_the_archive_title() );

	} else {

		if (has_post_thumbnail() ) {
			$image = get_the_post_thumbnail_url();

		} else {
			$custom_logo_id = get_theme_mod( 'custom_logo' );
			$image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
			$image = $image[0];
		}

		$permalink = get_permalink();
		$title = get_the_title();
		$description = get_the_excerpt();
	}

	// Open Graph
	echo '<meta property="og:title" content="' . $title . '" />';
	echo '<meta name="description" content="'. $description . '">';
	echo '<meta property="og:type" content="website" />';
	echo '<meta property="og:url" content="' . $permalink . '" />';
	echo '<meta property="og:image" content="' . $image . '" />';

	// Twitter Card
	echo '<meta name="twitter:card" content="summary_large_image">';
	echo '<meta property="twitter:domain" content="' . get_home_url() . '">';
	echo '<meta property="twitter:url" content="' . $permalink . '">';
	echo '<meta name="twitter:title" content="' . $title  . '">';
	echo '<meta name="twitter:description" content="' . $description .'">';
	echo '<meta name="twitter:image" content="' . $image  . '">';

}
add_action('wp_head', 'jd_opengraph_meta_tags');
<?php
/**
 *  Enable Post Formats
 *  https://developer.wordpress.org/themes/functionality/post-formats/#formats-in-a-child-theme
 */
add_action( 'after_setup_theme', 'jd_twentytwentythree_post_formats' );
function jd_twentytwentythree_post_formats() {
    $post_formats = array( 'aside', 'image', 'gallery', 'video', 'audio', 'chat', 'link', 'quote', 'status' );
    add_theme_support( 'post-formats', $post_formats);
}
/*
Theme Name:   JD Twenty Twenty Three Child
Description:  Twenty Twenty Three Child Theme
Author:       Joseph Dickson
Author URI:   https://joseph-dickson.com
Template:     twentytwentythree
Version:      1.0.0
License:      GNU General Public License v2 or later
License URI:  http://www.gnu.org/licenses/gpl-2.0.html
Text Domain:  twentytwentythree
*/

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.