אם יצרתם טקסונומיה לסוג תוכן מותאם (Custom Post Type) מסוים ואינכם רואים אותה כשאת עורכים את אותו CPT בגוטנברג, אז וודאו כי אתם מוסיפים את השורה 'show_in_rest' => true
גם לארגומנטים של ה CPT וגם לאלו של הטקסונומיה.

כולנו מסכימים שתוספי וורדפרס מועילים ומקלים עלינו בהמון סיטואציות. אך ייתכן ומספר שורות בקובץ functions.php של התבנית שלכם יחסוך מכם את הצורך להוסיף פלאגין נוסף לאתר שלכם.
בארכיון זה תמצאו מגוון רחב של סניפטים וקטעי קוד (Code Snippets) המאפשרים שינויים ומודיפיקציה לוורדפרס ולאופן פעולתה. אלו בעצם קטעי קוד קצרים וקולעים שנאספו במרוצת השנים.
בכל פעם שאני נתקל בקטע קוד שימושי אני מוסיפו למאגר, אז אם יש לכם סניפט מסויים שאתם מעוניינים לשתף, אשמח אם תשלחו אותו ואוסיפו למכלול הסניפטים.
אם יצרתם טקסונומיה לסוג תוכן מותאם (Custom Post Type) מסוים ואינכם רואים אותה כשאת עורכים את אותו CPT בגוטנברג, אז וודאו כי אתם מוסיפים את השורה 'show_in_rest' => true
גם לארגומנטים של ה CPT וגם לאלו של הטקסונומיה.
ג'ון מולר מסביר מה קורה כשמשנים את כתובות ה URL של אתרים, ואילו צעדים עליך לנקוט כדי לוודא שגוגל תוכל להוסיף את האתר לאינדקס.
האם אתם טוענים את הקובץ rtl.css
בדרך האוטומטית שוורדפרס מספקת? כלומר הוספת הקובץ rtl.css
לספריית התבנית שלכם, כך שבמידה ושפת האתר מוגדרת כשפה מימין לשמאל (RTL) קובץ זה יטען אוטומטית, היא הדרך המעודפת לטעינת קובץ CSS ספציפי להגדרות CSS ספציפיות באתרי RTL.
אך קובץ זה אינו בעל גירסה (כלומר ללא query string), דבר המקשה על ניקוי הקאש בדפדפן ספציפית עבור קובץ זה (אם אינכם משתמשים בתוסף קאש כלשהו).
לכן, בכדי להוסיף את הפרמטר ver
לאחר הקובץ rtl.css
בהתאם לזמן בו שונה הקובץ לאחרונה, תוכלו להשתמש בפילטר הבא:
add_filter( 'locale_stylesheet_uri', function ($localized_stylesheet_uri) {
$time_ver = filemtime( get_stylesheet_directory() . '/rtl.css' );
return add_query_arg( array('ver' => $time_ver), $localized_stylesheet_uri );
});
אם אתם מעוניינים לשנות את התנהגות המגניפיקציה (Zoom) במעבר עכבר על מוצר בעמוד המוצר של ווקומרס, תוכלו לעשות זאת באמצעות הפילטר woocommerce_single_product_zoom_options
:
add_filter( 'woocommerce_single_product_zoom_options', 'custom_single_product_zoom_options' );
function custom_single_product_zoom_options( $zoom_options ) {
// Changing the magnification level:
$zoom_options['magnify'] = 0.7;
return $zoom_options;
}
ואלו הפרמטרים שבאפשרותכם לשנות:
$zoom_options = array (
'url' => false,
'callback' => false,
'target' => false,
'duration' => 120, // Transition in milli seconds (default is 120)
'on' => 'mouseover', // other options: grab, click, toggle (default is mouseover)
'touch' => true, // enables a touch fallback
'onZoomIn' => false,
'onZoomOut' => false,
'magnify' => 1, // Zoom magnification: (default is 1 | float number between 0 and 1)
);
כשרושמים את הטקסונומיה (register_taxonomy) ניתן פשוט להשתמש במערך באופן הבא:
register_taxonomy( 'artist', array( 'profile', 'cd' ), $args );
אולי אתם יודעים ואולי לא, אך ניתן לשנות או לקבוע את אורך התקציר (excerpt) בוורדפרס באמצעות הפילטר הבא:
function sv_excerpt_length( $length ) {
return 15;
}
add_filter( 'excerpt_length', 'sv_excerpt_length' );
אך זה יקבע אורך תקציר מסויים כל פעם שתשתמשו בפונקציה the_excerpt. ומה אתם מעוניינים להשתמש באורך תקציר שונה במקומות שונים בתבנית שלכם? במקרה זה תוכלו להשתמש בקוד הבא (functions.php
):
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt) >= $limit) {
array_pop($excerpt);
$excerpt = implode(" ", $excerpt) . '...';
} else {
$excerpt = implode(" ", $excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);
return $excerpt;
}
לאחר מכן תוכלו לקבוע את אורך התקציר בתבנית שלכם באופן הבא:
<?php echo excerpt(25); ?>
ניתן במקרה זה להשתמש בפילטר הבא לטובת העניין:
add_filter( 'get_the_archive_title', function ($title) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>' ;
} elseif ( is_tax() ) { //for custom post types
$title = sprintf( __( '%1$s' ), single_term_title( '', false ) );
} elseif (is_post_type_archive()) {
$title = post_type_archive_title( '', false );
}
return $title;
});
הסניפט הבא יאפשר לכם לבדוק האם בפוסט מסויים יש ״תוכן מוטמע״ (Embedded Content). עובד בתוך הלולאה תוך שימוש במזהה הפוסט (Post ID). לחילופין ניתן להעביר ID כלשהו ולבדוק אם בפוסט זה קיים אותו תוכן מוטמע.
<?php
function has_embed( $post_id = false ) {
if( !$post_id ) $post_id = get_the_ID();
else $post_id = absint( $post_id );
if( !$post_id ) return false;
$post_meta = get_post_custom_keys( $post_id );
$post_meta = array_map( 'trim' , $post_meta );
foreach( $post_meta as $meta ) {
if( '_oembed' != substr( $meta , 0 , 7 ) )
continue;
return true;
}
return false;
}
והשימוש בו מתבצע כך:
if( has_embed() ) {
// do whatever
}
הסניפט הבא מאפשר לכם להכניס תוכן אוטומטי לכל פוסט טייפ (לכל סוג תוכן) חדש שתיצרו. הוסיפו לקובץ functions.php
:
<?php
////////////////////////////////////////////////////////////////////////////////////
// This auto populates post types and posts.
///////////////////////////////////////////////////////////////////////////////////
function my_editor_content( $content ) {
global $post_type;
switch( $post_type ) {
case 'your_post_type_here': //auto populate
$content = 'The content you want to pre-populate the post type with.';
break;
}
return $content;
}
add_filter( 'default_content', 'my_editor_content' );
הנה כיצד להוסיף CSS ל ACF בממשק הניהול. במקרה זה, גרמנו ל Repeater Fields להיות בעלי הפרדה ברורה יותר. בוצעו גם מספר שינויים נוספים בכדי שההבנה של הממשק תהיה נוחה יותר:
<?php
function my_acf_admin_head() { ?>
<style type="text/css">
.acf-flexible-content .layout .acf-fc-layout-handle {
background-color: #202428;
color: #eee;
}
.acf-repeater.-row > table > tbody > tr > td,
.acf-repeater.-block > table > tbody > tr > td {
border-top: 2px solid #202428;
}
.acf-repeater .acf-row-handle {
vertical-align: top !important;
padding-top: 16px;
}
.acf-repeater .acf-row-handle span {
font-size: 20px;
font-weight: bold;
color: #202428;
}
.imageUpload img {
width: 75px;
}
.acf-repeater .acf-row-handle .acf-icon.-minus {
top: 30px;
}
</style>
<?php
}
add_action( 'acf/input/admin_head', 'my_acf_admin_head' );
ובמקרה של ה Repeater זו התוצאה.. שמים לב לקו המפריד?