Visualizzazione 0 filoni di risposte
Visualizzazione 0 filoni di risposte
- Devi essere connesso per rispondere a questo topic.
Email: info@wpitaly.it
Home › Forum › Plugin e temi di WP › Trasformare automaticamente parole in url?
Salve, mi chiedevo vi è un modo per far sà¬, attraverso qualche modifica al template, che alcune parole diventino automaticamente degli url?
Es in una notizia uno scrive forum e automaticamente diventa un link che porta al proprio forum. In modo diciamo da non dover ogni volta mettere l’url manualmente.
Ho provato a seguire questa guida che ho trovato online:
How to do it manually
It just so happens that replacing one thing with another is quite easy in PHP. You can get it done by implementing just one simple function and then including it in the functions.php file of your current theme.
Without further ado, here’s the function:
function replace_keywords_fn($where)
{
//MODIFY HERE
$KWs = array(’1st keyword’, ’2nd keyword’);
$URLs = array(‘http://google.com’, ‘http://yahoo.com’);
//nothing to do below this line
$pattern = array();
$replacement = array();
for($i=0; $i<count($KWs); $i++)
{
$pattern2 = ‘/<a[^>]*>(.*?)’.$KWs[$i].’(.*?)</a>/’;
if(preg_match($pattern2, $where))
continue;
$pattern[$i] = ‘/([ ][!$%&()*+,./:;@_{}-])(‘.$KWs[$i].’)([ ][!$%&()*+,./:;@_{}-])/’;
$replacement[$i] = ‘123′;
}
return preg_replace($pattern, $replacement, $where, 1);
}
add_filter(‘content_save_pre’,'replace_keywords_fn’);
Ma come modifico il file function il template si sballa tutto.
Alternativamente meglio usare un plugin? Preferirei non aggiungerne un altro giusto per un paio di link.
WPItaly - Copyright Creative Commons: CC BY-NC-SA 4.0