Hi Heike,
Do you have the full error message available? All I can tell you from that is that the error occurred on line 11 of a snippet.
Hi @bungeshea ,
here is the complete error message:
Undefined variable $post in xxxxx/wordpress/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()'d code on line 11
Attempt to read property "ID" on null in xxxxx/wordpress/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()'d code on line 11
I found the snippet that is causing the error – thanks to your help with the search function 🙂
But now I’m stuck, cause I don’t know how to repair the snippet code – would you mind helping me?
Here is the code:
// Add featured image to RSS feed
add_filter('the_excerpt_rss', 'j0e_imagetoRSS');
add_filter('the_content_feed', 'j0e_imagetoRSS');
function j0e_imagetoRSS($content)
{
$label = 'Tags: ';
if (has_post_thumbnail()) {
$content = '
' . get_the_post_thumbnail($post->ID, 'zuki-medium-portrait', array('style' => 'max-width: 100%; height: auto; margin-bottom: 10px;')) . '
' . $content .
'
' . $label . j0e_show_tags() . '';
}
return $content;
}
// Creates the tags list
function j0e_show_tags()
{
$post_tags = get_the_tags();
$separator = ' | ';
$output = '';
if (!empty($post_tags)) {
foreach ($post_tags as $tag) {
$output .= 'term_id)) . '">#' . $tag->name . '' . $separator;
}
}
return trim($output, $separator);
}
It is the line with the “$post->ID” in it.
That would be really really kind 🙂
Thanks
Heike
-
This reply was modified 3 years ago by
HighKay.
Looks like some of that snippet is missing – specifically the part that creates the tag links. I’ve tried to recreate it where I can, and hopefully strengthened the code to prevent PHP errors.
$callback = function ( $content ) {
if ( has_post_thumbnail() ) {
$thumbnail = get_the_post_thumbnail(
null,
'zuki-medium-portrait',
array( 'style' => 'max-width: 100%; height: auto; margin-bottom: 10px;' )
);
$tags = '';
$tag_objects = get_the_tags();
if ( $tag_objects ) {
$tag_links = [];
foreach ( $tag_objects as $tag ) {
$tag_links[] = sprintf(
'<a href="%s">#%s</a>',
esc_url( get_tag_link( $tag ) ),
esc_html( $tag->name )
);
}
$label = 'Tags: ';
$tags = $label . join( ' | ', $tag_links );
}
$content = $thumbnail . $content . $tags;
}
return $content;
};
// Add featured image to RSS feed
add_filter( 'the_excerpt_rss', $callback );
add_filter( 'the_content_feed', $callback );
@bungeshea – Thank you sooooooo much!!!!
That works perfectly 🙂
I really appreciate your fast & perfect support!
Thanks a lot 🙂
-
This reply was modified 3 years ago by
HighKay.