• Super User

    mi segno a questo post che mi interessa tantissimo...ora sono di fretta, poi dirò la mia 😉

    PS: con Fabio avevamo in mente una mezza idea di crearne uno simile ma che fosse piu sito che blog... 😉


  • Bannato Super User

    Grazie Giorgio per questo tuo spunto, perchè proprio in questi giorni sto iniziando a lavorare su wordpress ed i tuoi consigli, come sempre, saranno di grande aiuto per me e molti altri.

    :ciauz:


  • Community Manager

  • User

    ho modificato il file header.php di wordpress così:
    (la parte inziale è rimasta modificata, ho modifcato solo quello in grassetto)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http&#58;//www.w3.org/1999/xhtml">
    
    <head profile="http&#58;//gmpg.org/xfn/11">
    	<meta http-equiv="Content-Type" content="<?php bloginfo&#40;'html_type'&#41;; ?>; charset=<?php bloginfo&#40;'charset'&#41;; ?>" />
    
    	
    	SOTTO E' LA PARTE MODIFICATA
    <title> <?php wp_title&#40;&#41;; ?> </title> 
    <meta name="keywords" content="<?php wp_title&#40;&#41;; ?>" /> 
    <meta name="description" content="<?php wp_title&#40;&#41;; ?>" />
    
    

    ora il titolo della pagina appare così:
    » una giornata al mare
    » mi son comprato la macchina
    ...

    cioè inizia sempre con questo segno** »** !!
    voglio togliere** » **
    cosa devo modificare per eliminare questo problema???


  • Community Manager

    Non ci ho mai pensato, il codice html di quel >> è »


  • Super User

    Ciao allora la funzione che genera quella stringa si trova nel file wordpress\wp-includes\template-functions-general.php ed e' la seguente:```
    function wp_title($sep = '»', $display = true) {
    global $wpdb;
    global $m, $year, $monthnum, $day, $category_name, $month, $posts;

    	$cat = get_query_var&#40;'cat'&#41;;
    	$p = get_query_var&#40;'p'&#41;;
    	$name = get_query_var&#40;'name'&#41;;
    	$category_name = get_query_var&#40;'category_name'&#41;;
    
    // If there's a category
    if&#40;!empty&#40;$cat&#41;&#41; &#123;
        if &#40;!stristr&#40;$cat,'-'&#41;&#41; &#123; // category excluded
            $title = get_the_category_by_ID&#40;$cat&#41;;
        &#125;
    &#125;
    if &#40;!empty&#40;$category_name&#41;&#41; &#123;
        if &#40;stristr&#40;$category_name,'/'&#41;&#41; &#123;
            $category_name = explode&#40;'/',$category_name&#41;;
            if &#40;$category_name&#91;count&#40;$category_name&#41;-1&#93;&#41; &#123;
                $category_name = $category_name&#91;count&#40;$category_name&#41;-1&#93;; // no trailing slash
            &#125; else &#123;
                $category_name = $category_name&#91;count&#40;$category_name&#41;-2&#93;; // there was a trailling slash
            &#125;
        &#125;
        $title = $wpdb->get_var&#40;"SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'"&#41;;
    &#125;
    
    // If there's a month
    if&#40;!empty&#40;$m&#41;&#41; &#123;
        $my_year = substr&#40;$m, 0, 4&#41;;
        $my_month = $month&#91;substr&#40;$m, 4, 2&#41;&#93;;
        $title = "$my_year $sep $my_month";
    
    &#125;
    if &#40;!empty&#40;$year&#41;&#41; &#123;
        $title = $year;
        if &#40;!empty&#40;$monthnum&#41;&#41; &#123;
            $title .= " $sep ".$month&#91;zeroise&#40;$monthnum, 2&#41;&#93;;
        &#125;
        if &#40;!empty&#40;$day&#41;&#41; &#123;
            $title .= " $sep ".zeroise&#40;$day, 2&#41;;
        &#125;
    &#125;
    
    // If there's a post
    if &#40;is_single&#40;&#41; || is_page&#40;&#41;&#41; &#123;
        $title = strip_tags&#40;$posts&#91;0&#93;->post_title&#41;;
        $title = apply_filters&#40;'single_post_title', $title&#41;;
    &#125;
    
    // Send it out
    if &#40;$display && isset&#40;$title&#41;&#41; &#123;
        echo " $sep $title";
    &#125; elseif &#40;!$display && isset&#40;$title&#41;&#41; &#123;
        return " $sep $title";
    &#125;
    

    }
    In particolare ti interessa la prima riga:
    function wp_title($sep = '»', $display = true)

    La variabile ```
    $sep = '&raquo;'
    ``` e' proprio il separatore, che di default e' &raquo; che corrisponde a ».
    Se cancelli &raquo; dovresti risolvere il tuo problema. Pero' il separatore non uscirebbe piu' nemmeno quando invece servirebbe.
    

    function wp_title($sep = '', $display = true)

    
    La cosa ideale da fare sarebbe fare un semplice copia-incolla e creare una nuova funzione wp_title2, nello stesso file, identica alla prima tranne per il nome e per il fatto che non inserisce il separatore. Cosi' puoi utilizzare quella per inserire i meta tag. :)

  • User

    La cosa ideale da fare sarebbe fare un semplice copia-incolla e creare una nuova funzione wp_title2, nello stesso file, identica alla prima tranne per il nome e per il fatto che non inserisce il separatore. Cosi' puoi utilizzare quella per inserire i Meta Tag

    grazie claudioweb 🙂

    posso chiederti come e dove creare la nuova funzione wp_title2 ?


  • Super User

    Semplicemente sotto a quella gia' presente:```
    function wp_title($sep = '»', $display = true) {
    global $wpdb;
    global $m, $year, $monthnum, $day, $category_name, $month, $posts;

    	$cat = get_query_var&#40;'cat'&#41;;
    	$p = get_query_var&#40;'p'&#41;;
    	$name = get_query_var&#40;'name'&#41;;
    	$category_name = get_query_var&#40;'category_name'&#41;;
    
    // If there's a category
    if&#40;!empty&#40;$cat&#41;&#41; &#123;
        if &#40;!stristr&#40;$cat,'-'&#41;&#41; &#123; // category excluded
            $title = get_the_category_by_ID&#40;$cat&#41;;
        &#125;
    &#125;
    if &#40;!empty&#40;$category_name&#41;&#41; &#123;
        if &#40;stristr&#40;$category_name,'/'&#41;&#41; &#123;
            $category_name = explode&#40;'/',$category_name&#41;;
            if &#40;$category_name&#91;count&#40;$category_name&#41;-1&#93;&#41; &#123;
                $category_name = $category_name&#91;count&#40;$category_name&#41;-1&#93;; // no trailing slash
            &#125; else &#123;
                $category_name = $category_name&#91;count&#40;$category_name&#41;-2&#93;; // there was a trailling slash
            &#125;
        &#125;
        $title = $wpdb->get_var&#40;"SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'"&#41;;
    &#125;
    
    // If there's a month
    if&#40;!empty&#40;$m&#41;&#41; &#123;
        $my_year = substr&#40;$m, 0, 4&#41;;
        $my_month = $month&#91;substr&#40;$m, 4, 2&#41;&#93;;
        $title = "$my_year $sep $my_month";
    
    &#125;
    if &#40;!empty&#40;$year&#41;&#41; &#123;
        $title = $year;
        if &#40;!empty&#40;$monthnum&#41;&#41; &#123;
            $title .= " $sep ".$month&#91;zeroise&#40;$monthnum, 2&#41;&#93;;
        &#125;
        if &#40;!empty&#40;$day&#41;&#41; &#123;
            $title .= " $sep ".zeroise&#40;$day, 2&#41;;
        &#125;
    &#125;
    
    // If there's a post
    if &#40;is_single&#40;&#41; || is_page&#40;&#41;&#41; &#123;
        $title = strip_tags&#40;$posts&#91;0&#93;->post_title&#41;;
        $title = apply_filters&#40;'single_post_title', $title&#41;;
    &#125;
    
    // Send it out
    if &#40;$display && isset&#40;$title&#41;&#41; &#123;
        echo " $sep $title";
    &#125; elseif &#40;!$display && isset&#40;$title&#41;&#41; &#123;
        return " $sep $title";
    &#125;
    

    }

    function wp_title2($sep = '', $display = true) {
    global $wpdb;
    global $m, $year, $monthnum, $day, $category_name, $month, $posts;

    	$cat = get_query_var&#40;'cat'&#41;;
    	$p = get_query_var&#40;'p'&#41;;
    	$name = get_query_var&#40;'name'&#41;;
    	$category_name = get_query_var&#40;'category_name'&#41;;
    
    // If there's a category
    if&#40;!empty&#40;$cat&#41;&#41; &#123;
        if &#40;!stristr&#40;$cat,'-'&#41;&#41; &#123; // category excluded
            $title = get_the_category_by_ID&#40;$cat&#41;;
        &#125;
    &#125;
    if &#40;!empty&#40;$category_name&#41;&#41; &#123;
        if &#40;stristr&#40;$category_name,'/'&#41;&#41; &#123;
            $category_name = explode&#40;'/',$category_name&#41;;
            if &#40;$category_name&#91;count&#40;$category_name&#41;-1&#93;&#41; &#123;
                $category_name = $category_name&#91;count&#40;$category_name&#41;-1&#93;; // no trailing slash
            &#125; else &#123;
                $category_name = $category_name&#91;count&#40;$category_name&#41;-2&#93;; // there was a trailling slash
            &#125;
        &#125;
        $title = $wpdb->get_var&#40;"SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'"&#41;;
    &#125;
    
    // If there's a month
    if&#40;!empty&#40;$m&#41;&#41; &#123;
        $my_year = substr&#40;$m, 0, 4&#41;;
        $my_month = $month&#91;substr&#40;$m, 4, 2&#41;&#93;;
        $title = "$my_year $sep $my_month";
    
    &#125;
    if &#40;!empty&#40;$year&#41;&#41; &#123;
        $title = $year;
        if &#40;!empty&#40;$monthnum&#41;&#41; &#123;
            $title .= " $sep ".$month&#91;zeroise&#40;$monthnum, 2&#41;&#93;;
        &#125;
        if &#40;!empty&#40;$day&#41;&#41; &#123;
            $title .= " $sep ".zeroise&#40;$day, 2&#41;;
        &#125;
    &#125;
    
    // If there's a post
    if &#40;is_single&#40;&#41; || is_page&#40;&#41;&#41; &#123;
        $title = strip_tags&#40;$posts&#91;0&#93;->post_title&#41;;
        $title = apply_filters&#40;'single_post_title', $title&#41;;
    &#125;
    
    // Send it out
    if &#40;$display && isset&#40;$title&#41;&#41; &#123;
        echo " $sep $title";
    &#125; elseif &#40;!$display && isset&#40;$title&#41;&#41; &#123;
        return " $sep $title";
    &#125;
    

    }

    Il copia-incolla e' il miglior amico dei programmatori ;)

  • User

    ok, quindi:

    • creo wp_title2 nel file "wordpress\wp-includes*template-functions-general.php*"

    • modifico nel file "header.php"
      <title> <?php wp_title(); ?> </title>

    con

    <title> <?php wp_title2(); ?> </title>

    GIUSTO???

    PS. ma aggiungere tutto quell'altro codice nel file "wordpress\wp-includes*template-functions-general.php*" non è che rende troppo pesante il processo???


  • Super User

    @platinum said:

    ok, quindi:

    • creo wp_title2 nel file "wordpress\wp-includes*template-functions-general.php*"

    • modifico nel file "header.php"
      <title> <?php wp_title(); ?> </title>

    con

    <title> <?php wp_title2(); ?> </title>

    GIUSTO???

    PS. ma aggiungere tutto quell'altro codice nel file "wordpress\wp-includes*template-functions-general.php*" non è che rende troppo pesante il processo???Si giusto. Non si tratta di operazioni che richiedono grandi risorse... sono solo poche righe. Il server dovra' solo lavorare un pochino in piu', mentre il codice che gli utenti del sito vedranno sara' pulito come prima.

    Certo si potrebbe anche provare a riscriverla un po' piu' snella la funzione, dovrebbero bastare solo poche righe di codice. Ma alla fine il risultato non cambia... quindi mi risparmio la fatica :microsoft:


  • User

    claudioweb ti ringrazio non solo per la mano che mi hai dato nel postare il codice modificato, ma soprattutto per la chiarezza espositiva 🙂

    :ciauz:


  • User
    <title> <?php wp_title2&#40;&#41;; ?> - <?php bloginfo&#40;'name'&#41;; ?> - </title>
    <meta name="keywords" content="<?php wp_title2&#40;&#41;; ?>" /> 
    <meta name="description" content="<?php wp_title2&#40;&#41;; ?>" />
    

    solo per precisione: per quanto riguarda il <title> conviene adottare questo formato con "-" ai lati di <?php bloginfo('name'); ?> per una maggiore chiarezza visiva nel title

    oppure usare ":" o "|" o un altro segno

    questo per evitare che in categorie, archivi e altrove si creino confusioni tra titolo del blog e titolo dell'articolo (post)

    :ciauz:


  • Super User

    In generale userei | ma in questo caso per uniformarmi a wordpress userei proprio » cioe' » . 😉


  • Ho visto che facendo queste modifiche però non si vede il titolo nella index, personalmente ho modificato così

    
    <title><?php if &#40; is_home&#40;&#41; || is_page&#40;&#41; &#41; &#123; ? bloginfo&#40;'description'&#41;; &#125; ?><?php wp_title&#40;&#41;; ?></title>
    

    Se siamo nella index il <?php wp_title(); ?> rimane vuoto ma gli faccio stampare la descrizione del sito che personalmente ho messo come parola chiave più importante. Mentre nelle pagine interne stampa solo il titolo dell'articolo.

    :ciauz:


  • Super User

    Visto che mi sembra (In Topic) :lol: segnalo questo post per l'ottimizzazione di WP: http://www.yellow-llama.com/2005/seo-your-wordpress-blog/

    :ciauz: