Home › Forum › Plugin e temi di WP › Mettere una funzione a inizio head
-
AutorePost
-
-
28 Maggio 2017 alle 23:48 #31432miki31-7Partecipante
Salve, ho AMP sul mio sito tramite il plugin “AMP”, e nel suo file amp-frontend-actions c’è la funzione qui sotto che aggiunge il codice link rel=”amphtml” linkando alla pagina AMP dall’articolo originale.
Il link rel=amphtml però appare verso la fine della sezione head, mentre io voglio che appaia verso l’inizio, quindi all’inizio di wp_head, perchè sospetto che i motori facciano fatica a rilevarlo immediatamente e perchè è davvero anti-estetico. Potete aiutarmi? Ve ne sarei immensamente grato
<?php
// Callbacks for adding AMP-related things to the main theme
add_action( 'wp_head', 'amp_frontend_add_canonical' );
function amp_frontend_add_canonical() {
if ( false === apply_filters( 'amp_frontend_show_canonical', true ) ) {
return;
}
$amp_url = amp_get_permalink( get_queried_object_id() );
printf( '<link rel="amphtml" href="%s" />', esc_url( $amp_url ) );
}
Il mio sito https://goo.gl/aseLEmNon credo faccia differenza dov’è hostato ma dato che è un’info richiesta: shared hosting Linux Aruba
-
29 Maggio 2017 alle 6:51 #121640SteveAglAmministratore del forum
occorre modificare il plugin cambiando la priorita alla ad_action, ma cosଠpoi perdi gli aggiornamenti, che sia in basso o in alto non cambia nulla, i motori lo leggono sicuramente, la sua posizione non influenza per ulla la cosa, non vedo proprio il problema.
-
29 Maggio 2017 alle 8:07 #121641miki31-7Partecipante
Grazie per la risposta! Riusciresti a spiegarmi come modificare la priorità in quel codice? Io ci ho provato ma non ci riesco… Mi serve anche per ordinare altro codice nell’head perché stanno veramente messi male, tra cui anche quello di Analytics che vorrei inserire tramite funzione
-
29 Maggio 2017 alle 8:30 #121642SteveAglAmministratore del forum
ma ripeto sse cambi il plugin poi avrai da rimodificarlo ad ogni aggiornamento, sinceramente non capisco il problema del “sta messo male” è codice non visibile all’utente ai motori che sia impaginato bene o tutto di fila non cambia di una vioirgola… ripeto sono NON PROBLEMI
-
29 Maggio 2017 alle 12:49 #121643miki31-7Partecipante
Allora come si spiegano questi problemi?
– Di giorno in giorno, Google sta de-indicizzando tutte le mie pagine AMP sulla Search Console
– Ho 200 pagine AMP duplicate, mostrate sempre sulla Search Console
– Questi duplicati ogni tot di giorni spariscono per essere sostituiti da altre pagine duplicate in numero maggiore di quelle precedenti
Le pagine AMP sono correttamente implementate, ho usato i tool di Google per verificarle, ho messo il canonical nella versione AMP e il link amphtml in quella originale. Allora perchè Google continua a disindicizzarle? L’unica spiegazione che trovo è che Google non riesca sempre a riconoscere il tag amphtml, magari perchè c’è qualche codice sbagliato prima di esso che rende invalido il resto, colpa quindi del tema o di plugin WordPress. Ecco perchè voglio provare a mettere rel amphtml all’inizio del wp head, fermo restando che non sono esperto e che quello che dici tu potrebbe comunque essere vero… Comunque se non riesci a elaborarmi un codice grazie comunque del consiglio!
In quanto ad Analytics, l’ho messo subito prima del tag /head, posizione sconsigliata perchè c’è l’hook wp_head, perciò volevo spostarlo altrove iniettandolo tramite function, anche se questo è un problema secondario.
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.