WORDPRESS

TRADUZIONE STRINGHE

Metodo 1
function ijab_change_string( $translated_text, $text, $domain ) {
$translated_text = str_replace(OLD TEXT’, ‘NEW TWXT’, $translated_text);
return $translated_text;
}
add_filter( ‘gettext’, ‘ijab_change_string’, 100, 3 );

Metodo 2
add_filter(‘gettext’, ‘translate_reply’);
add_filter(‘ngettext’, ‘translate_reply’);
function translate_reply($translated) {
$translated = str_ireplace(‘No Result Found!’, ‘Nessun Risultato Trovato!’, $translated);
$translated = str_ireplace(‘The products you requested could not be found. Try changing your module settings or add some new products.’, ‘Non è stato possibile trovare i prodotti richiesti. Prova a modificare le impostazioni del modulo o ad aggiungere nuovi prodotti.’, $translated);
return $translated;
}

Fix the JQuery Is Not Defined Error

Add a Snippet to the wp-config

/** Absolute path to the WordPress directory. */
if ( !defined(‘ABSPATH’) )
define(‘ABSPATH’, dirname(__FILE__) . ‘/’);
define(‘CONCATENATE_SCRIPTS’, false);

NASCONDERE WARNING WORDPRESS

in wp-config

define(‘WP_DEBUG’, false);

se non funziona, sostituire la riga con

ini_set(‘display_errors’,’Off’);
ini_set(‘error_reporting’, E_ALL );
define(‘WP_DEBUG’, false);
define(‘WP_DEBUG_DISPLAY’, false);

Custom script in body

//——————————-
// Custom script in body
//——————————-

function av_google_tag_body(){
?>
<!– Google Tag Manager (noscript) –>
<noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-MTF6838S”
height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
<!– End Google Tag Manager (noscript) –>
<?php
}
add_action(‘wp_body_open’, ‘av_google_tag_body’);

// Custom script in body END

ALTERNATIVA

function gtagmanag() {
echo ‘<!– Google Tag Manager –>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({“gtm.start”:new Date().getTime(),event:”gtm.js”});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!=”dataLayer”?”&l=”+l:””;j.async=true;j.src=”https://www.googletagmanager.com/gtm.js?id=”+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,”script”,”dataLayer”,”GTM-MJRT9249″);</script>
<!– End Google Tag Manager –>’;
}
add_action( ‘wp_head’, ‘gtagmanag’, -10000 );
function noscript() {
echo ‘<!– Google Tag Manager (noscript) –>
<noscript><iframe src=https://www.googletagmanager.com/ns.html?id=GTM-MJRT9249
height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
<!– End Google Tag Manager (noscript) –>’;
}
add_action( ‘wp_body_open’, ‘noscript’ );

UPLOADARE FILE CON ESTENSIONE NON CANONICA

Aggiungere in wp-config

define('ALLOW_UNFILTERED_UPLOADS', true);

NB una volta fatto l’upload RIMUOVRERE la riga – Attenzione agli apostrofi

INSERIRE TESTO DESCRIZIONE CATEGORIA

add this code to your functions.php file in your (child) theme:

add_shortcode(‘cat_desc’, ‘cat_desc_shortcode’);
function cat_desc_shortcode() {

global $wp_query;
$cat = $wp_query->get_queried_object();

if( $cat == null ) return;

$output = nl2br($cat->description);
return $output;
}

————————————————————————-
use the shortcode [cat_desc] in your layout, where you would like the category description to appear

Listare Post in Ordine Alfabetico

function pluginize_order_cpt_by_title( $query ) {
if ( ! is_admin() ) {
return;
}

if ( ! $query->is_main_query() ) {
return;
}

$screen = get_current_screen();
if ( ! is_object( $screen ) ) {
return;
}

if ( ‘NOME-DEL-POST’ === $screen->post_type ) {
$query->set( ‘orderby’, ‘title’ );
$query->set( ‘order’, ‘ASC’ );
}
}
add_action( ‘pre_get_posts’, ‘pluginize_order_cpt_by_title’ );

RANKMATH META DESCRIPTION

/* prevent the global meta description from being overwritten when an excerpt is entered */

add_action( ‘rank_math/frontend/description’, function( $description ) {
global $post;
$post_meta_description = RankMath\Post::get_meta( ‘description’, $post->ID );

if ( $post_meta_description ) {
return $post_meta_description;
}

if ( is_single() ) {
$desc = RankMath\Helper::get_settings( “titles.pt_{$post->post_type}_description” );
if ( $desc ) {
return RankMath\Helper::replace_vars( $desc, $post );
}
}

return $description;
});

DIVI

DIVI PORTFOLIO GALLERY THUMB SIZE

/* GALLERY THUMB SIZE */
add_filter( ‘et_pb_portfolio_image_height’, ‘portfolio_size_h’ );
add_filter( ‘et_pb_portfolio_image_width’, ‘portfolio_size_w’ );
function portfolio_size_h($height) {
return ‘675’;
}
function portfolio_size_w($width) {
return ‘1080’;
}

DIVI GALLERY 3 COLONNE

@media (min-width: 1100px) {
/* Set the image widths */

.et_pb_gallery_grid .et_pb_gallery_item,
.et_pb_gallery_grid .column_width,
.et_pb_gallery_grid .et_pb_gallery_image,
.et_pb_gallery_grid .et_pb_gallery_image.portrait img {
width: 310px !important;
}
.et_pb_gallery_grid .et_pb_gallery_image img {
min-width: 310px;
}
/* Set the image heights */

.et_pb_gallery_grid .et_pb_gallery_image,
.et_pb_gallery_grid .et_pb_gallery_image.landscape img {
height: 310px !important;
}
.et_pb_gallery_grid .et_pb_gallery_image img {
min-height: 310px;
}
/* Set the spacing between images */

.et_pb_gallery_grid .gutter_width {
width: 30px;
}
.et_pb_gallery_grid .et_pb_gallery_item {
margin-bottom: 30px !important;
}
.et_pb_gallery_grid .et_pb_gallery_item {
clear: none !important;
}
.et_pb_gallery_grid .et_pb_gallery_item:nth-child(3n) {
margin-right: 0 !important;
}
.et_pb_gallery_grid .et_pb_gallery_item:nth-child(3n+1) {
clear: both !important;
}
.et_pb_gallery_grid .et_pb_gallery_item {
margin-right: 30px !important;
}
.et_pb_gallery_grid .et_pb_gallery_image img {
min-height: 0 !important;
}
.et_pb_gallery_grid .et_pb_gallery_image,
.et_pb_gallery_grid .et_pb_gallery_image.landscape img {
height: auto !important;
}
}

MENU MOBILE FIXED

/* Fix Mobile Menu Top */
.et_fixed_nav #main-header { position: fixed; }

BLANK DIVI LIBRARY ELEMENTS

Se accedendo a un modulo, riga o sezione salvati nella libreria dovessero essere “vuoti” per risolvere occorre (ri)salvare i permalink

ERRORE IMPORT DEMO DATA TEMA

Abbassare temporaneamente la versione PHP a 7.4
oppure
Polling back to version 4.24.0 and increasing the max_execution_time value to 300

PLACE BUTTON MODULES NEXT TO EACH OTHER IN THE SAME COLUMN

Find the row and column where you want to place the buttons.
In the column settings, go to the Advanced tab to the CSS Class.
Add the class “pa-inline-buttons” and save.
Next, add the following snippet your Divi>Theme Options>Custom CSS box.

/*place button modules next to each other in the same column*/
.pa-inline-buttons .et_pb_button_module_wrapper { display: inline-block; }

PRIMO CAMPO ACCORDION CHIUSO

Place the following jQuery in Divi > Theme Options > Integration > Add code to the < head > of your blog

<script>
jQuery(function($){
$(‘.et_pb_accordion .et_pb_toggle_open’).addClass(‘et_pb_toggle_close’).removeClass(‘et_pb_toggle_open’);

$(‘.et_pb_accordion .et_pb_toggle’).click(function() {
$this = $(this);
setTimeout(function(){
$this.closest(‘.et_pb_accordion’).removeClass(‘et_pb_accordion_toggling’);
},700);
});
});
</script>

Internal Link Fix

DIVI > INTEGRAZIONE > Aggiungi codice a < head > del tuo blog
NB modifcare valore var headerHeight = 160; a seconda dell’altezza dell’header

<!– Internal Link Fix –>
<script>
jQuery(function($) {
window.et_pb_smooth_scroll = function( $target, $top_section, speed, easing ) {
var $window_width = $( window ).width();
$menu_offset = -1;
var headerHeight = 160;
if ( $ (‘#wpadminbar’).length && $window_width <= 980 ) {
$menu_offset += $( ‘#wpadminbar’ ).outerHeight() + headerHeight;
} else {
$menu_offset += headerHeight;
}
//fix sidenav scroll to top
if ( $top_section ) {
$scroll_position = 0;
} else {
$scroll_position = $target.offset().top – $menu_offset;
}
// set swing (animate’s scrollTop default) as default value
if( typeof easing === ‘undefined’ ){
easing = ‘swing’;
}
$( ‘html, body’ ).animate( { scrollTop : $scroll_position }, speed, easing );
}
});
</script>
<!– End Internal Link Fix –>

Rendere URL Video Dinamico (ACF)

// Make the Video URL field Dynamic

add_filter(‘et_builder_get_parent_modules’, function($modules){
foreach ($modules as $module_slug => $module) {
if($module_slug === ‘et_pb_video’ && isset($module->fields_unprocessed)){
$module->fields_unprocessed[‘src’][‘dynamic_content’] = ‘url’;
$module->fields_unprocessed[‘src_webm’][‘dynamic_content’] = ‘url’;
}
}
return $modules;
});

FIX APERTURA MEDIA

Disabilitare su Rank Math la voce “Reindirizza gli allegati”
NB occorre ricaricare file rinominato e risalvare 

MAIL DI CONFERMA FORM

/* Confirmation Mail */
add_action( ‘et_pb_contact_form_submit’, ‘dbc_divi_contact_form_confirmation’, 10, 3 );
function dbc_divi_contact_form_confirmation($processed_fields_values, $et_contact_error, $contact_form_info) {
if ( true === $et_contact_error ) {
return;
}
// Configuration
$email_field_id = ‘Email’;
$subject = ‘Conferma Invio Richiesta Informazioni’;
$message = ‘Grazie per la tua iscrizione, sarete ricontattati quanto prima.’;
// Send the confirmation email
$email_field_id = strtolower($email_field_id);
if (isset($processed_fields_values[$email_field_id][‘value’])) {
$email = $processed_fields_values[$email_field_id][‘value’];
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
wp_mail($email, $subject, $message);
}
}
}

DIVI MOBILE MENU SCROLLABLE

It works with the default mobile menu of Divi theme, as well as with the menus created using the Menu and Fullwidth Menu modules, you just need to add the scrollable_mobile_menu CSS class in the module settings Advanced -> CSS ID & Classes -> CSS Class field.

/** * Make Divi mobile menu scrollable. * **/
@media (max-width: 980px) {
#et_mobile_nav_menu .et_mobile_menu,
.scrollable_mobile_menu.et_pb_menu .et_mobile_menu,
.scrollable_mobile_menu.et_pb_fullwidth_menu .et_mobile_menu {
max-height: 65vh; /* Adjust this value as needed */
overflow-y: auto;
}
}

COLONNA CON COLORE SFONDO IN DIAGONALE

/* Diagonal Green Column */
@media screen and (min-width: 981px) {
.diagonal-green-column-1 { z-index: 9; }
.diagonal-green-column-1::after {
content: ”;
position: absolute;
-webkit-transform: skew(-10deg);
transform: skew(-10deg);
width: 120px;
height: calc(100% – 0px);
top: 0px;
background-color: #006139;
right: -57px;
z-index:9;
}
}

PROBLEMA CARICAMENTO ICONE

Divi> Themes Options> General > Performance
Disabilitare Icone dinamiche

AGGIUNGERE ID A FORM E SUBMIT + CONSENT MODE IUBENDA

Inserire in functions.php

/* *** FORM CONSENT MODE *** */
function custom_jquery_script() {
    ?>
    <script type=”text/javascript”>
        jQuery(document).ready(function($) {
            // Assegna un ID al form
            $(‘#et_pb_contact_form_0 .et_pb_contact_form’).attr(‘id’, ‘modulo-contatti’);
 
            // Assegna un ID al pulsante di invio
            $(‘#et_pb_contact_form_0 .et_pb_contact_submit’).attr(‘id’, ‘modulo-contatti-submit’);
 
// Assegna name=”generic” al checkbox privacy
            $(‘#et_pb_contact_privacy_11_0’).attr(‘name’, ‘generic’);
        });
    </script>
 
<script type=”text/javascript”>
    _iub.cons_instructions.push([“load”, {
        submitElement: document.getElementById(“modulo-contatti-submit”),
        form: {
            selector: document.getElementById(“modulo-contatti”),
            map: {
                subject: {
                    first_name: “et_pb_contact_nome_0”,
    last_name: “et_pb_contact_cognome_0”,
                    email: “et_pb_contact_email_0”
                },
                preferences: {
                    generic: “generic”
                }
            }
        },
        consent: {
            legal_notices: [{
                    identifier: “privacy_policy”,
                },
                {
                    identifier: ‘cookie_policy’,
                }
            ],
        }
    }])
</script>
 
    <?php
}
add_action(‘wp_footer’, ‘custom_jquery_script’);
HEADER SENZA STILE AL CARICAMENTO DELLA PAGINA

Per risolvere il problema di Divi che mostra intestazioni e contenuti senza stile durante il caricamento della pagina inserire in Divi > Theme Options > Integration > Add code to the < head > of your blog

<script type="text/javascript">
var elm=document.getElementsByTagName("html")[0];
elm.style.display="none";
document.addEventListener("DOMContentLoaded",function(event) {elm.style.display="block"; });
</script>

 

LARGHEZZA SOTTOMENU AUTOMATICA

/*set the Divi menu dropdown auto width*/
@media only screen and (min-width: 981px) {
.nav li ul {
width: fit-content;
display: flex;
flex-direction: column;
}
.nav li li {
white-space: nowrap;
}
.nav li li a {
width: auto !important;
}
}

WOOCOMMERCE

WooCommerce: Show 4 Products per Row

https://divibooster.com/woocommerce-show-4-products-per-row-in-divi/

@media screen and (min-width:1024px) {
    .woocommerce ul.products li.product { 
width: 21% !important;
margin: 2% !important;
clear: none !important;
    }
    .woocommerce ul.products li.product:nth-child(4n+1) {
clear: both !important;
    }
}
@media screen and (min-width: 768px) and (max-width: 980px) {
    .woocommerce ul.products li.product.first, .woocommerce ul.products li.product.last {
        clear: right !important;
    }
    .woocommerce ul.products li.product:nth-child(4n+1) {
         clear: none !important;
    }
}

MODIFICARE TESTO PULSANTE "LEGGI TUTTO"

in functions.php

/* Change the Read More Button Text to Custom Text */
add_filter( ‘gettext’, ‘ds_change_readmore_text’, 20, 3 );
function ds_change_readmore_text( $translated_text, $text, $domain ) {
if ( ! is_admin() && $domain === ‘woocommerce’ && $translated_text === ‘Leggi tutto’) {
$translated_text = ‘Vedi Scheda’;
}
return $translated_text;
}

 

DIVI WOOCOMMERCE PRODOTTI MOBILE 2 COLONNE

@media screen and (max-width: 479px) {
.et_gallery_item:nth-child(n), .et_pb_column .et_pb_filterable_portfolio .et_pb_portfolio_item.et_pb_grid_item:nth-child(n), .et_pb_column .et_pb_grid_item:nth-child(n), .et_pb_column .et_pb_shop_grid .woocommerce ul.products li.product:nth-child(n), .et_pb_column .woocommerce ul.products li.product:nth-child(n), .woocommerce-page ul.products li.product:nth-child(n) {
width: 45.25%!important;
margin: 0 9.5% 9.5% 0!important;
}
.et_gallery_item:nth-child(2n), .et_pb_column .et_pb_grid_item:nth-child(2n), .et_pb_column .et_pb_shop_grid .woocommerce ul.products li.product:nth-child(2n), .et_pb_column .woocommerce ul.products li.product:nth-child(2n), .woocommerce-page ul.products li.product:nth-child(2n) {
margin-right: 0!important;
}
}

MOSTRARE SOLO FREE SHIPPING SE DISPONIBILE

/** Hide shipping rates when free shipping is available.  **/

function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( ‘free_shipping’ === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty( $free ) ? $free : $rates;
}
add_filter( ‘woocommerce_package_rates’, ‘my_hide_shipping_when_free_is_available’, 100 );

 

VISIBILE SOLO LA HOME - ALTRE PAGINE BLANK

(ri)salvare i permalink

CSS

Troncare contenuto testuale

.nome-classe-contenitore {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 4;
line-clamp: 4;
overflow: hidden;
}

Hide image titles on hover

/* Hide image titles on hover */
img { pointer-events: none; }

JAVASCRIPT

Uguaglia Altezza DIV

<script>
equalheight = function(container){

var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;
$(container).each(function() {

$el = $(this);
$($el).height(‘auto’)
topPostion = $el.position().top;

if (currentRowStart != topPostion) {
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
rowDivs.length = 0; // empty the array
currentRowStart = topPostion;
currentTallest = $el.height();
rowDivs.push($el);
} else {
rowDivs.push($el);
currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
}
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
});
}

$(window).load(function() {
equalheight(‘.contenitore .contenuto’);
});

$(window).resize(function(){
equalheight(‘.contenitore .contenuto’);
});
</script>

ACF

Modifica del Post Type Key

Se si modifica il Post Type Key per un CPT occorre poi riassociare gli articoli.

Accedi a phpMyAdmin
Esegui una Query SQL

  • Vai alla scheda SQL e inserisci il seguente comando, sostituendo nuovo_post_type con il tuo nuovo “Post Type Key” e vecchio_post_type con il tipo di post corrente delle tue pagine:
sql
UPDATE wp_posts 
SET post_type = 'nuovo_post_type' 
WHERE post_type = 'vecchio_post_type';

Nota: Se il tuo prefisso del database non è wp_, ricordati di sostituirlo con il tuo prefisso.

Aggiorna ACF
Assicurati che il gruppo di campi ACF sia configurato per il nuovo post type, come descritto nei passaggi precedenti.

/////////////////////////////////////////

Se non dovessero essere listate le pagine
Prelevare l’ID di un post cercandolo su DB ed editarlo dal pannello WordPress inserendo l’ID https://www.nomedominio.it/wp-admin/post.php?post=283684&action=edit&lang=it

Salvando dovrebbero poi visualizzarzi correttamente tutti i posts.

WP FORMS

Nome