Wp media import (WP-CLI)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
Import inclusief attributen
Wat je kunt terugvinden in de broncode (de afbeelding is niet klikbaar): Originele bestandsnaam en Alt-text

Met wp media import kun je afbeeldingen importeren inclusief attributen, en allerlei bijbehorende truuks uithalen. Wat je niet lijkt te kunnen doen: De bestandsnaam aanpassen (dus dat de bestandsnaam na import anders is dan daarvoor).

Attributen

Deels overgenomen van WPBeginner.com:

Bestandsnaam

Zie SEO » Afbeeldingen - Bestandsnaam

Title

The title field in the attachment details allow you to provide a title to your image. This title is used internally by WordPress to sort images in the media library.

Caption

This is the text that you want to display with your image. Depending on your theme, it will be displayed inside image border or outside the image. See our guide on how to add caption to images in WordPress.

Alt text

Zie SEO » Afbeeldingen - Alt-tekst

Description

This text can be displayed on the attachment page for your image. You can enter as much information as you want in the description field. Like the story behind a photograph, how you took the picture, or anything else that you want to share can go here. You can even add links in the description field.

Bestandsnaam aanpassen?

Standaard lijk je niet de bestandsnaam te kunnen aanpassen:

Dat kun je dus het beste vantevoren doen.

Voorbeelden

Import zonder attributen

Script:

#!/bin/bash

# Import an image without attributes
####################################
#
cd /var/www/rt_tmp.dvb
wp media import /home/strompf/RT.ww/060-Metadata-import/EscobillasIndustriales.jpg

Shell:

./importtest 

Imported file '/home/strompf/RT.ww/060-Metadata-import/EscobillasIndustriales.jpg' as attachment ID 1306.
Success: Imported 1 of 1 items.

Als ik het commando herhaal, wordt de afbeelding opnieuw geïmporteerd, maar met een ander ID. Je krijgt dus meerdere instanties vanhetzelfde object.

Import met attributen

Script:

#!/bin/bash

# Image including attributes
############################
#
cd /var/www/rt_tmp.dvb
wp media import \
	/home/strompf/RT.ww/060-Metadata-import/windmolen_338x225.jpg \
	--title="Various carbon brushes, with one resembling a windmill" \
	--caption="We have lots of these, and w're creative, too!" \
	--alt="Create image of a bunch of carbon brushes" \
	--desc="Various carbon brushes, to have an impression of our assortment" \

Shell:

./importtest 

Imported file '/home/strompf/RT.ww/060-Metadata-import/windmolen_338x225.jpg' as attachment ID 1307.
Success: Imported 1 of 1 images.

Metadata met whitespace

Dit commando is gegenereerd in een rekenblad. Vandaar dat opmaak niet optimaal is. Het werkt prima:

wp media import /home/strompf/RT.ww/Productafbeeldingen/080-Afbeeldingen_voor_alle_talen/Widget-wiel-40x50x10-Smurf-wheel-rad.jpg --title="Widget-wiel met afmetingen 40x50x10 (mm) voor Smurf-systemen" --caption="Widget-wiel met afmetingen 40x50x10 (mm) voor Smurf-systemen" --alt="Widget-wiel 40x50x10 met SKU wheel_40x050x10 te koop op example.com.com" --desc="Widget-wiel voor Smurf-systemen. Afmetingen:

<ul>
<li> Dim1: 40mm – 1.5748 Inch
<li> Dim2: 50mm – 1.9685 Inch
<li> Dim3: 10mm – 0.3937 Inch
</ul>
"

Inclusief auteur

Merk op dat de twee-voorlaatste " op de volgende regel is beland. Sois.

wp media import /home/strompf/RT.ww/Productafbeeldingen/080-Afbeeldingen_voor_alle_talen/Widget-wiel-40x50x10-Smurf-wheel-rad.jpg --title="Widget-wiel met afmetingen 40x50x10 (mm) voor Smurf-systemen" --caption="Widget-wiel met afmetingen 40x50x10 (mm) voor Smurf-systemen" --alt="Widget-wiel 40x50x10 met SKU wheel_40x050x10 te koop op example.com.com" --desc="Widget-wiel voor Smurf-systemen. Afmetingen:

<ul>
<li> Dim1: 40mm – 1.5748 Inch
<li> Dim2: 50mm – 1.9685 Inch
<li> Dim3: 10mm – 0.3937 Inch
</ul>
" --user="Jeroen Strompf"

Zie ook

Bronnen