Hallo Jens,
verwendest du den Code in einem Plugin oder in der functions.php
deines Themes?
Du hast bereits eine Abfrage „wenn der Beitrag/die Seite ein Beitragsbild hat“ und musst das nur mit einem else
ergänzen:
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'full', array( 'style' => 'height: auto;margin-bottom:2em;max-width: 600px !important;padding-top: 0.75em;width: 100% !important;' ) ) . '' . $content;
} else {
/* bei Plugin bitte get_template_directory_uri() . '/images/default-thumbnail.png
mit plugins_url('/images/default-thumbnail.png', __FILE__); ersetzen */
$content = '<img src="' . get_template_directory_uri() . '/images/default-thumbnail.png" style="height: auto; margin-bottom:2em; max-width: 600px !important; padding-top: 0.75em; width: 100% !important;">' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
(was das Aneinanderhängen leerer Textstrings (z.B. '' . $content
) bewirken soll, ist mir allerdings nicht ganz klar?) 🙂
Moin Bego,
erstmal VIELEN DANK!
Ich habe es per functions.php eingebunden.
Wenn ich es richtig verstehe kann ich nun also den Code zu umändern:
} else {
/* bei Plugin bitte get_template_directory_uri() . '/images/default-thumbnail.png
mit plugins_url('/images/default-thumbnail.png', __FILE__); ersetzen */
$content = '<img src="https://url.de/media-uploads/Icon-RSS.jpg" style="height: auto; margin-bottom:2em; max-width: 600px !important; padding-top: 0.75em; width: 100% !important;">' . $content;
}
return $content;
}
??
Das mit dem . $content; habe ich von dieser Seite: https://www.wprssaggregator.com/feed-featured-images/
-
Diese Antwort wurde geändert vor 5 Jahren, 8 Monaten von JensGoro.
Wenn ich es richtig verstehe kann ich nun also den Code zu umändern:
Ich hatte dir doch schon fertigen Code mitgeteilt?
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = get_the_post_thumbnail( $post->ID, 'full', array( 'style' => 'height: auto;margin-bottom:2em;max-width: 600px !important;padding-top: 0.75em;width: 100% !important;' ) ) . $content;
} else {
$content = '<img src="' . get_template_directory_uri() . '/images/default-thumbnail.png" style="height: auto; margin-bottom:2em; max-width: 600px !important; padding-top: 0.75em; width: 100% !important;">' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
(Diesmal um die leeren Strings bereinigt.)
Das ist korrekt. Sorry dann habe ich es falsch formuliert. Kann ich mit deinem Code wie in meinem Beispiel nun auch URL Bilder angeben, um diese zb. Von einer Subdomain zu nehmen?
Hast du dir den Code denn mal angeschaut? 🙂
Was wird
<img src="' . get_template_directory_uri() . '/images/default-thumbnail.png">
wohl laden?
Du kannst natürlich auch eine URL fest eintragen … oder müsstest ein paar mehr Informationen liefern, was auf der Subdomain installiert ist: eine andere WordPress-Installation? Eine Website einer Multisite?
Nachtrag: Sorry, jetzt verstehe ich was du meinst. War ein Missverständnis … Das müsste so gehen, ja.
-
Diese Antwort wurde geändert vor 5 Jahren, 8 Monaten von Bego Mario Garde. Grund: Nachtrag
Ja, ich habe mir den Code angesehen.. Klar.. img src wird auch externe Bilder laden 🙂
Ich habes eben den Code aktualisiert, doch leider wird das bild nicht geladen 🙁
Meine Feed URL:
https://bit.ly/2OplHI5
Der Code:
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = get_the_post_thumbnail( $post->ID, 'full', array( 'style' => 'height: auto;margin-bottom:2em;max-width: 600px !important;padding-top: 0.75em;width: 100% !important;' ) ) . $content;
} else {
$content = '<img src="https://images.dealscout24.de/Dealscout24-Logo-compressor.png" style="height: auto; margin-bottom:2em; max-width: 600px !important; padding-top: 0.75em; width: 100% !important;">' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
Stehe ich gerade etwas auf dem Schlauch?
Hm, ich weiß nicht ob das Beitragsbild in einem eigenen Absatz stehen muss. Probier mal
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '<p>' . get_the_post_thumbnail( $post->ID, 'full', array( 'style' => 'height: auto;margin-bottom:2em;max-width: 600px !important;padding-top: 0.75em;width: 100% !important;' ) ) . '</p>' . $content;
} else {
$content = '<p>' . '<img src="' . get_template_directory_uri() . '/images/default-thumbnail.png" style="height: auto; margin-bottom:2em; max-width: 600px !important; padding-top: 0.75em; width: 100% !important;">' . '</p>' .$content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
Danke, @pixolin, aber leider klappt auch dieser nicht.
Aktuell zeigt der genannte Feed für jeden Beitrag ein Beitragsbild. Vielleicht kannst du noch mal einen neuen Testbeitrag ohne Beitragsbild hinzufügen?