Default featured image

Beschrijving

Voeg een standaard uitgelichte afbeelding toe aan de pagina met media-instellingen. Deze uitgelichte afbeelding zal getoond worden wanneer er geen uitgelichte afbeelding is ingesteld. Zo simpel is het.

Take a look at FAQ for the basic questions.
Feel free to contact me on the forum or on the github repository.

Schermafdrukken

  • De instelling op de mediapagina
  • De mediamanager begint met de huidige geselecteerde afbeelding

Installatie

  1. Pak de map uit in de /wp-content/plugins/ map
  2. Activeer de plugin via het ‘Plugins’ menu in WordPress
  3. Ga naar de instellingen->media pagina en selecteer een afbeelding.

FAQ

De door mij gekozen uitgelichte afbeelding wordt niet weergegeven, waarom werkt deze niet?

This plugin works out of the box for most cases, but not always. If it doesn’t work you can try the following things.

  • Switch themes. Most of the time the theme does something weird.
  • Are you using the Core WordPress functions to get the image? (see the FAQ below this one).
  • Do normal feature images work?
  • Might it be hidden via css? DFI images have an extra default-featured-img class added to them.

Still having problems? I want to know if it fails, so contact me

Welke functies kan ik gebruiken om de uitgelichte afbeelding weer te geven?

There are no new functions, all core WordPress functions can be used.

Can I set a different image for a custom post type?

Yes, the following code will set a different image.

add_filter( 'dfi_thumbnail_id', 'dfi_posttype_book', 10, 2 );
function dfi_posttype_book( $dfi_id, $post_id ) {
    $post = get_post( $post_id );
    if ( 'book' === $post->post_type ) {
        return 31; // the image id for the book post type.
    }

    return $dfi_id; // the original featured image id.
}

Can I set different images per category?

Yes, the following snippet will set different images based on the category.

add_filter( 'dfi_thumbnail_id', 'dfi_category', 10, 2 );
function dfi_category( $dfi_id, $post_id ) {
    // Set a different image for posts that have the 'cats' category set.
    // This will trigger first, if multiple categories have been set.
    if ( has_category( 'cats', $post_id ) ) {
        return 7; // cats img id.
    }
    // Set a different image for posts that have the 'cats' category set.
    if ( has_category( 'dogs', $post_id ) ) {
        return 8; // dogs img id.
    }

    return $dfi_id; // the original featured image id.
}

Can I change the HTML of the default featured image?

When a Default Featured Image is used it will already add an extra class default-featured-img.
This can be used for styling.

If you need more you can change the whole HTML with the filter dfi_thumbnail_html.

add_filter( 'dfi_thumbnail_html', 'dfi_add_class', 10, 5 );
function dfi_add_class( $html, $post_id, $default_thumbnail_id, $size, $attr ) {
    // Add a class to the existing class list.
    $attr['class'] .= ' my-class';

    return wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
}

Can I exclude one page from having a Default Featured Image?

The following code will exclude the post/page with ID 23.

add_filter( 'dfi_thumbnail_id', 'dfi_skip_page', 10, 2 );
function dfi_skip_page( $dfi_id, $post_id ) {
    if ( $post_id == 23 ) {
        return 0; // invalid id.
    }

    return $dfi_id; // the original featured image id.
}

Beoordelingen

14 maart 2024
Default featured image does what it's supposed to do and it meets two criteria I always look for: light weight it just works The support forum has good answers to questions, and that's a big plus.Thanks for the great plugin.
12 januari 2024 1 reactie
Es perfecto porque hay una opción que te pone automáticamente la imagen destacada de todos los post que no la tenían cogiendo la primera imagen del post y si no hay imagen lo deja vacío. Perfecto!!
31 juli 2023
Great plugin that does exactly what it claims to do. I have a client site that is using Elementor and it doesn't allow you to specify a default image on the Blog Archive. This plugin resolved that issue, allowing you to specify a default Featured Image. Thanks for creating such a useful plugin 👍👍
Lees alle 63 beoordelingen

Bijdragers & ontwikkelaars

“Default featured image” is open source software. De volgende personen hebben bijgedragen aan deze plugin.

Bijdragers

“Default featured image” is vertaald in 12 talen. Dank voor de vertalers voor hun bijdragen.

Vertaal “Default featured image” naar jouw taal.

Interesse in ontwikkeling?

Bekijk de code, haal de SVN repository op, of abonneer je op het ontwikkellog via RSS.

Changelog

1.7.3

  • PHP 7.4 and WP 6.2 are now required. This is to use the new WP_HTML_Tag_Processor functions.
  • Fixed a bug where classes were overridden.

1.7.2.1

  • Development is now done in git.

1.7.2

  • Added extra context to a translation as suggested by Alex Lion

1.7.1

  • Rare SVN uitrol bug opgelost.

1.7.0

  • hoofdklasse verplaatst naar zijn eigen bestand.
  • Tweede klasse toegevoegd die uitzonderingen met andere plug-ins kan bevatten
  • De eerste uitzondering is voor WP User Frontend
  • De tweede uitzondering is voor WP All Import.

1.6.4

  • get_post_meta($post_id) zonder de meta_key op te geven vond geen DFI. Het gebruikt nu een dieper niveau en stelt het in in de kerncache.

1.6.3

  • Pluginheader aangepast die het installeren ervan blokkeerde.

1.6.2

  • Plugin volgt nu WP-coderingsstandaard
  • Een kleine bug opgelost waarbij DFI de uitgelichte afbeeldingen van bijlages overschrijft. mp3 heeft standaard een muzieknoot, DFI dient dat niet te overschrijven.

1.6.1

  • Kleine readme.txt update.

1.6

  • Een van de laatste aanpassingen hield geen rekening met alle situaties.

1.5

  • Twee kleine (en zeldzame) waarschuwingen opgelost
  • Vertaaldomein toegevoegd

1.4

  • Pluginafbeeldingen toegevoegd, zowel de plugin header als de thumbnail. Gebaseerd op de boot die WP.org gebruikt in zijn themavoorbeelden
  • Een bug opgelost waarbij de AJAX-verzoeken de DFI forumthread niet retourneerden

1.3

  • Filter dfi_thumbnail_id retourneert nu ook de bericht-ID van het bericht (of een ander berichttype) dat wordt aangeroepen. Zie de FAQ voor nieuwe voorbeelden

1.2

  • Filter dfi_thumbnail_id wordt nu in een eerder stadium aangeroepen.

1.1

  • Overervingsklassen van de afbeelding aangepast

1.0

  • Plugin zal nu de instellingen verwijderen bij het verwijderen van de plugin
  • een standaardklasse aan de <img> tag toegevoegd als deze een standaard uitgelichte afbeelding toont
  • De standaard uitgelichte afbeelding retourneert nu ook via get_post_thumbnail_id, waardoor de kans dat het mislukt veel kleiner wordt.
  • De afbeelding op de mediapagina wordt nu gevalideerd

0.9

  • Lancering