for front page, show the Featured Image of the Page 33 (front page)
This commit is contained in:
@@ -44,6 +44,21 @@ final class Ruady_OG_Head {
|
|||||||
public static function render_head_markup(): void {
|
public static function render_head_markup(): void {
|
||||||
// Adjust this if you only want standard posts:
|
// Adjust this if you only want standard posts:
|
||||||
// if ( ! is_singular( 'post' ) ) { return; }
|
// if ( ! is_singular( 'post' ) ) { return; }
|
||||||
|
|
||||||
|
if ( is_front_page() ) {
|
||||||
|
$html = self::build_markup_for_front_page();
|
||||||
|
if ( $html === '' ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
echo "\n" . $html . "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! is_singular() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( ! is_singular() ) {
|
if ( ! is_singular() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -86,6 +101,42 @@ final class Ruady_OG_Head {
|
|||||||
return $desc . $ellipsis;
|
return $desc . $ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string $page_headline = "Da Ruady. Hansdampf in allen Gassen.";
|
||||||
|
|
||||||
|
private static function build_markup_for_front_page(): string {
|
||||||
|
|
||||||
|
$site_title = get_bloginfo( 'name' );
|
||||||
|
$site_url = site_url();
|
||||||
|
$site_url_p = parse_url($site_url);
|
||||||
|
$site_host = $site_url_p['host'];
|
||||||
|
|
||||||
|
$og_image_url = get_the_post_thumbnail_url(33, 'full');
|
||||||
|
$description = self::$page_headline;
|
||||||
|
$og_description = self::$page_headline;
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
?>
|
||||||
|
<meta name="description" content="<?php echo esc_attr( $description ); ?>">
|
||||||
|
|
||||||
|
<!-- Open Graph Meta Tags -->
|
||||||
|
<meta property="og:url" content="<?php echo esc_url( $site_url ); ?>">
|
||||||
|
<meta property="og:type" content="website">
|
||||||
|
<meta property="og:title" content="<?php echo esc_attr( $site_title ); ?>">
|
||||||
|
<meta property="og:description" content="<?php echo esc_attr( $og_description ); ?>">
|
||||||
|
<meta property="og:image" content="<?php echo esc_url( $og_image_url ) ?>">
|
||||||
|
|
||||||
|
<!-- Twitter Meta Tags -->
|
||||||
|
<meta name="twitter:card" content="summary_large_image">
|
||||||
|
<meta property="twitter:domain" content="<?php echo esc_attr( $site_host ); ?>">
|
||||||
|
<meta property="twitter:url" content="<?php echo esc_url( $site_url ); ?>">
|
||||||
|
<meta name="twitter:title" content="<?php echo esc_attr( $site_title ); ?>">
|
||||||
|
<meta name="twitter:description" content="<?php echo esc_attr( $og_description ); ?>">
|
||||||
|
<meta property="twitter:image" content="<?php echo esc_url( $og_image_url ) ?>">
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return trim( (string) ob_get_clean() );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the head markup for one post.
|
* Build the head markup for one post.
|
||||||
*/
|
*/
|
||||||
@@ -105,7 +156,7 @@ final class Ruady_OG_Head {
|
|||||||
|
|
||||||
$og_image_url = user_trailingslashit( trailingslashit( $post_url ) . 'og-image' );
|
$og_image_url = user_trailingslashit( trailingslashit( $post_url ) . 'og-image' );
|
||||||
$description = self::make_description(wp_strip_all_tags( $excerpt ));
|
$description = self::make_description(wp_strip_all_tags( $excerpt ));
|
||||||
$og_description = "Da Ruady. Hansdampf in allen Gassen.";
|
$og_description = self::$page_headline;
|
||||||
|
|
||||||
// Example business logic:
|
// Example business logic:
|
||||||
// - add a meta tag for every post
|
// - add a meta tag for every post
|
||||||
@@ -202,7 +253,7 @@ final class Ruady_OG_Head {
|
|||||||
$accent = imagecolorallocate( $image, 204, 235, 235 ); // theme tertiary (light blue)
|
$accent = imagecolorallocate( $image, 204, 235, 235 ); // theme tertiary (light blue)
|
||||||
|
|
||||||
imagefilledrectangle( $image, 0, 0, $width, $height, $bg );
|
imagefilledrectangle( $image, 0, 0, $width, $height, $bg );
|
||||||
imagefilledrectangle( $image, 0, $height-30, $width, $height, $accent );
|
imagefilledrectangle( $image, 0, $height-10, $width, $height, $tt );
|
||||||
|
|
||||||
$title = wp_strip_all_tags( get_the_title( $post ) );
|
$title = wp_strip_all_tags( get_the_title( $post ) );
|
||||||
$site = wp_strip_all_tags( get_bloginfo( 'name' ) );
|
$site = wp_strip_all_tags( get_bloginfo( 'name' ) );
|
||||||
|
|||||||
Reference in New Issue
Block a user