¡todo el mundo! Necesito agregar el prefijo de dominio www, no escribir a mano, cada filtro como post_link, page_link, category_link, etc. Hay un filtro global para todas las URL agregadas www. Los métodos de cómo cambiar la configuración general en la URL del sitio en la base de datos o cambiar las opciones o htaccess, simplemente no encajan. Gracias de antemano por su respuesta.
Si no puede cambiarlo a través de wp-admin, puede usar lo siguiente:
add_filter( 'post_link', array($this, 'changePermalinks'), 10, 3);
add_filter( 'page_link', array($this, 'changePermalinks'), 10, 3);
add_filter( 'post_type_link', array($this, 'changePermalinks'), 10, 3);
add_filter( 'category_link', array($this, 'changePermalinks'), 11, 3);
add_filter( 'tag_link', array($this, 'changePermalinks'), 10, 3);
add_filter( 'author_link', array($this, 'changePermalinks'), 11, 3);
add_filter( 'day_link', array($this, 'changePermalinks'), 11, 3);
add_filter( 'month_link', array($this, 'changePermalinks'), 11, 3);
add_filter( 'year_link', array($this, 'changePermalinks'), 11, 3);
function changePermalinks($permalink, $post) {
if ( strpos($permalink, '://www.') ) return $permalink;
return str_replace('://', '://www.', $permalink);
}
En su tablero, vaya a Configuración -> General y la cuarta y quinta opción deberían ser “Dirección de WordPress (URL)” y “Dirección del sitio (URL)”. Cambiar el http://example.com
a http://www.example.com
y debería cambiar todos los enlaces.
-
Gracias por tu respuesta, pero esta solución no es para mí.
– SergeevDMS
25 de febrero de 2014 a las 16:36
-
Bien, ¿puedes explicar por qué esa no es la solución?
– Howli
25 de febrero de 2014 a las 16:48
-
Porque en nuestro alojamiento, esta opción se elimina del panel de administración.
– SergeevDMS
26 de febrero de 2014 a las 6:23
-
en 2016 esto en functions.php da como resultado una url en blanco
add_filter( 'post_link', array($this, 'changePermalinks'), 10, 3);function changePermalinks($permalink, $post) { $search = array('#devauthor#is','#author#is'); $replace = array('www','www'); $thePermalink = preg_replace($search, $replace, $permalink); return $thePermalink; }
– roberthuttinger
25/03/2016 a las 15:05
-
^ si no está en el contexto del objeto, entonces no debería usar
$this
palabra clave. asi seraadd_filter( 'post_link' , 'changePermalinks')
Opuesto aadd_filter( 'post_link' , array($this, 'changePermalinks'))
– Joe Hebilla
14/07/2017 a las 10:35