David Klhufek
Forum Replies Created
-
Hi @adaptiman,
I’ve updated and tested the code, and it now correctly displays the caption under the featured image in the Single Post template. The issue with the HTML link in the caption has been fixed as well.
/** * Add caption (Description) to the featured image in the Single Post template only. */ function add_featured_image_caption( $block_content, $block ) { if ( is_single() && isset($block['blockName']) && 'core/post-featured-image' === $block['blockName'] && has_post_thumbnail() ) { $thumbnail_id = get_post_thumbnail_id(); // Get the featured image ID // Retrieve the correct caption (stored in the "Description" field) $attachment = get_post($thumbnail_id); $caption = !empty($attachment->post_content) ? $attachment->post_content : ''; // Append the caption if it exists if ( ! empty( $caption ) ) { $block_content .= '<p class="featured-image-caption">' . wp_kses_post( $caption ) . '</p>'; } } return $block_content; } add_filter( 'render_block', 'add_featured_image_caption', 10, 2 );Try the updated version, and let me know if you need any further adjustments! 😊
Thank you for your quick response!
It turns out everything is fine — I had the “Hide Details” option checked, which was causing the issue. 😊
I appreciate your help!
Here is a solution to display the image caption for the featured image in the “Single Posts” template using WordPress filters. This will dynamically append the caption below the featured image. Copy and paste this code into your theme’s
functions.phpfile or a Code Snippets plugin.<?php
/**
* Add caption to the featured image in Single Posts template.
*/
// Add a caption below the featured image
function add_featured_image_caption( $block_content, $block ) {
// Check if the block is 'core/post-featured-image' and if the post has a featured image
if ( 'core/post-featured-image' === $block['blockName'] && has_post_thumbnail() ) {
$thumbnail_id = get_post_thumbnail_id(); // Get the featured image ID
$caption = wp_get_attachment_caption( $thumbnail_id ); // Get the image caption
// Append the caption to the block content if it exists
if ( $caption ) {
$block_content .= '<p class="featured-image-caption">' . esc_html( $caption ) . '</p>';
}
}
return $block_content;
}
// Hook the function to the render_block filter
add_filter( 'render_block', 'add_featured_image_caption', 10, 2 );Great, version 4.0.8 is fine. Tested on six websites.
Hi @badhonrocks
Today I tested version 4.0.7 and the bug is still there. The only version that works is 4.0.5
Hi, you need to add this code to custom CSS section in Customizer overview.
#site-header.top-header #site-logo #site-description h2 { color: #111; /*-- set your color --*/ }- This reply was modified 8 years, 9 months ago by David Klhufek.
- This reply was modified 8 years, 9 months ago by David Klhufek.
Forum: Themes and Templates
In reply to: [OceanWP] Better search results stylingForum: Themes and Templates
In reply to: [OceanWP] Next/Prev links on Custom Post TypesI tested what you wrote above, but it was not worked. Lately, I tried to copy original singular.php to new child file single-project.php then I add navigation code from Divi and viola it’s working now well. Anyway thank you for your time, we can close it.
Forum: Themes and Templates
In reply to: [OceanWP] Next/Prev links on Custom Post TypesYes, I use child theme oceanwp-child-theme-master, there is a file singular.php but I can’t find the place to reflect I need navigation for projects. Any idea?
Forum: Themes and Templates
In reply to: [OceanWP] Auto Featured ImageI found some explanation:
http://www.wpbeginner.com/beginners-guide/how-to-add-featured-image-or-post-thumbnails-in-wordpress/
and I solved my problem finally with plugin Easy Add Thumbnail
https://ww.wp.xz.cn/plugins/easy-add-thumbnail/- This reply was modified 8 years, 10 months ago by David Klhufek.
Forum: Themes and Templates
In reply to: [OceanWP] Auto Featured ImageOk, for example in Divi Epanel was a option Grab the first post image. In oldest themes that was default feature.
Forum: Plugins
In reply to: [Facebook Comments] Broken with WP-4.7.2 – No comments showI have more websites with this plugin installed, only http sites shows old comments now, https sites don’t show comments.
Forum: Plugins
In reply to: [YUZO] Yuzo broke Divi Theme editorthe error i get: Uncaught TypeError: $(…).wpColorPicker is not a function
Forum: Themes and Templates
In reply to: [evolve] Gallery code showing in PostsI found solution, if you use it like this:
Some text... <!--more--> [gallery link="file" columns="4" ids="190,191,192,193,194,195,196,197,198,199,200,201,202,203"]then no more code will be on excerpt. Hope it helps others.
Forum: Plugins
In reply to: [Slideshow Satellite] Will you be supporting WordPress 4.0Hi, I am in trouble, after update to WP 4.0 Satellite Slideshows are in reverse order. Last photo is first..
Do you plan to fix it?