<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[child theme: errore fatale con funzioni]]></title><description><![CDATA[<p dir="auto">Buonasera</p>
<p dir="auto">Sto personalizzando un child theme basato sul tema <em>twentyten</em>. Da quel che ho letto è possibile sovrascrivere anche le funzioni semplicemente creando nel child theme un documento <strong>functions.php</strong> ed inserendovi le nuove funzioni oppure quelle già presenti nel <strong>functions.php</strong> principale (in questo caso quello del tema <em>twentyten</em>) con le opportune modifiche. In questo modo le nuove funzioni da me inserite andranno a sovrascrivere o ad aggiungersi a quelle già esistenti.</p>
<p dir="auto">Nel fare questo finora non ho avuto alcun problema, poco fa però ho avuto la necessità di modificare la funzione <strong>twentyten_continue_reading_link</strong> e quindi, secondo quanto detto precedentemente, la ho copiata all'interno di <strong>functions.php</strong> del nuovo tema.</p>
<p dir="auto">Ecco cosa ho ottenuto:</p>
<p dir="auto"><strong>Fatal error</strong>:  Cannot redeclare twentyten_continue_reading_link()  (previously declared in  /my-site/wp-content/themes/my-child-theme/functions.php:33)  in <strong>/my-site/wp-content/themes/twentyten/functions.php</strong>  on line <strong>256</strong></p>
<p dir="auto">quale mistero si nasconde dietro a tutto questo?</p>
<p dir="auto">Grazie.</p>
]]></description><link>https://dev.connect.gt/topic/176078/child-theme-errore-fatale-con-funzioni</link><generator>RSS for Node</generator><lastBuildDate>Mon, 30 Nov 2026 06:23:15 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/176078.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 27 Aug 2012 19:39:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to child theme: errore fatale con funzioni on Wed, 29 Aug 2012 20:44:53 GMT]]></title><description><![CDATA[<p dir="auto">Sinceramente non lo so ma fa parte del codice di wordpress, se ti interessa ti rimando a questa lettura <a href="http://codex.wordpress.org/WordPress_Coding_Standards" rel="nofollow ugc">http://codex.wordpress.org/WordPress_Coding_Standards</a></p>
]]></description><link>https://dev.connect.gt/post/1083694</link><guid isPermaLink="true">https://dev.connect.gt/post/1083694</guid><dc:creator><![CDATA[elmanisero]]></dc:creator><pubDate>Wed, 29 Aug 2012 20:44:53 GMT</pubDate></item><item><title><![CDATA[Reply to child theme: errore fatale con funzioni on Wed, 29 Aug 2012 19:34:09 GMT]]></title><description><![CDATA[<p dir="auto">Una piccola curiosità: che cappero sta ad indicare (o a cosa serve) il termine che si trova tra virgolette ('twentyten-child' o 'twentyten' o 'twentyeleven' o qualsiasi altra cosa) e che si trova ovunque nei temi?</p>
<pre><code class="language-php">function yoda_twentyten_continue_reading_link() {
    return ' &lt;a href="'. get_permalink() . '"&gt;' . __( 'Continua a leggere &lt;span class="meta-nav"&gt;&amp;rarr;&lt;/span&gt;', 'twentyten-child' ) . '&lt;/a&gt;';
}
</code></pre>
]]></description><link>https://dev.connect.gt/post/1083702</link><guid isPermaLink="true">https://dev.connect.gt/post/1083702</guid><dc:creator><![CDATA[eugene]]></dc:creator><pubDate>Wed, 29 Aug 2012 19:34:09 GMT</pubDate></item><item><title><![CDATA[Reply to child theme: errore fatale con funzioni on Wed, 29 Aug 2012 17:47:31 GMT]]></title><description><![CDATA[<p dir="auto">Perfetto, non appena l'hosting torna attivo faccio dei test.</p>
<p dir="auto">Grazie ancora per l'aiuto e per i preziosi chiarimenti.</p>
]]></description><link>https://dev.connect.gt/post/1083701</link><guid isPermaLink="true">https://dev.connect.gt/post/1083701</guid><dc:creator><![CDATA[eugene]]></dc:creator><pubDate>Wed, 29 Aug 2012 17:47:31 GMT</pubDate></item><item><title><![CDATA[Reply to child theme: errore fatale con funzioni on Wed, 29 Aug 2012 17:32:01 GMT]]></title><description><![CDATA[<p dir="auto">In teoria si ma non garantisco nulla come sempre.</p>
]]></description><link>https://dev.connect.gt/post/1083693</link><guid isPermaLink="true">https://dev.connect.gt/post/1083693</guid><dc:creator><![CDATA[elmanisero]]></dc:creator><pubDate>Wed, 29 Aug 2012 17:32:01 GMT</pubDate></item><item><title><![CDATA[Reply to child theme: errore fatale con funzioni on Wed, 29 Aug 2012 16:48:51 GMT]]></title><description><![CDATA[<p dir="auto">Purtroppo in questo momento non sono al mio PC e quindi non posso verificare l'efficacia del codice da te indicato, tuttavia vediamo se ho ben capito la logica di tutto questo:</p>
<p dir="auto">definisco la nuova funzione <em>twentyten_continue_reading_link</em> assegnandole un nuovo nome:</p>
<pre><code class="language-php">function yoda_twentyten_continue_reading_link() {
    return ' &lt;a href="'. get_permalink() . '"&gt;' . __( 'Continua a leggere &lt;span class="meta-nav"&gt;&amp;rarr;&lt;/span&gt;', 'twentyten-child' ) . '&lt;/a&gt;';
}
</code></pre>
<p dir="auto">per sicurezza (o correttezza) definisco anche le funzioni che richiamano quella da me precedentemente definita:</p>
<pre><code class="language-php">function yoda_twentyten_auto_excerpt_more( $more ) {
    return ' &amp;hellip;' . yoda_twentyten_continue_reading_link();
}
</code></pre>
<p dir="auto">"informo" il sistema del fatto che invece di richiamare la funzione <em>twentyten_auto_excerpt_more</em> deve adesso richiamare <em>yoda_twentyten_auto_excerpt_more</em>:</p>
<pre><code class="language-php">function my_child_theme_setup() {
    remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
    add_filter( 'excerpt_more', 'yoda_twentyten_auto_excerpt_more' );
}
</code></pre>
<p dir="auto">non ho capito la sintassi ma credo che serva per rendere effettivo quanto dichiarato dalla precedente funzione:</p>
<pre><code class="language-php">add_action( 'after_setup_theme', 'my_child_theme_setup' );
</code></pre>
<p dir="auto">In definitiva, se io modifico una funzione (alterandone il nome) devo far attenzione ad intervenire anche in tutte le altre funzioni che la richiamano.<br />
Attraverso <em>remove_filter</em> e <em>add_filter</em> "comunico" successivamente al sistema il nome della nuova funzione al posto di quella vecchia.</p>
<p dir="auto">Qualcosa l'ho azzeccata?</p>
]]></description><link>https://dev.connect.gt/post/1083700</link><guid isPermaLink="true">https://dev.connect.gt/post/1083700</guid><dc:creator><![CDATA[eugene]]></dc:creator><pubDate>Wed, 29 Aug 2012 16:48:51 GMT</pubDate></item><item><title><![CDATA[Reply to child theme: errore fatale con funzioni on Wed, 29 Aug 2012 14:59:19 GMT]]></title><description><![CDATA[<p dir="auto">Neanche io so se può compromettere qualcos'altro. Cercando ho trovato questo, ma non so se funziona.</p>
<pre><code class="language-php">function yoda_twentyten_continue_reading_link() {
    return ' &lt;a href="'. get_permalink() . '"&gt;' . __( 'Continua a leggere &lt;span class="meta-nav"&gt;&amp;rarr;&lt;/span&gt;', 'twentyten-child' ) . '&lt;/a&gt;';
}

function yoda_twentyten_auto_excerpt_more( $more ) {
    return ' &amp;hellip;' . yoda_twentyten_continue_reading_link();
}

function my_child_theme_setup() {
    remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
    add_filter( 'excerpt_more', 'yoda_twentyten_auto_excerpt_more' );
}

add_action( 'after_setup_theme', 'my_child_theme_setup' );
</code></pre>
]]></description><link>https://dev.connect.gt/post/1083697</link><guid isPermaLink="true">https://dev.connect.gt/post/1083697</guid><dc:creator><![CDATA[elmanisero]]></dc:creator><pubDate>Wed, 29 Aug 2012 14:59:19 GMT</pubDate></item><item><title><![CDATA[Reply to child theme: errore fatale con funzioni on Wed, 29 Aug 2012 10:38:02 GMT]]></title><description><![CDATA[<p dir="auto">In effetti questa faccenda degli <em>hook</em> l'avevo letta ma avevo capito fosse applicabile solo ad alcune funzioni. La mia proverbiale pigrizia e la voglia di fare tutto e subito hanno fatto si che non approfondissi l'argomento.<br />
Vediamo se ci ho capito qualcosa:<br />
non potendo modificare un funzione non "pluggabile" devo prima risciverla con un altro nome nel <em>child theme</em> e poi eliminare l'originale dal <em>main theme</em>, sempre tramite uno script nel <em>child theme</em> in modo da non apportare mai alcuna modifica al tema principale. Fin qui abbastanza chiaro, ma nell'esempio viene riportata una funzione che applica un filtro, mentre la funzione che devo modificare io è completamente differente:</p>
<pre><code class="language-php">function twentyten_continue_reading_link() {
    return ' &lt;a href="'. get_permalink() . '"&gt;' . __( 'Continue reading &lt;span class="meta-nav"&gt;&amp;rarr;&lt;/span&gt;', 'twentyten' ) . '&lt;/a&gt;';
}
</code></pre>
<p dir="auto">Come dovrei procedere?<br />
Inoltre questa funzione viene anche richiamata da altre funzioni e non so se eseguire la suddetta operazione (ovvero eliminarla e sostituirla) può compromettere il corretto funzionamento dell'intero sistema.</p>
]]></description><link>https://dev.connect.gt/post/1083698</link><guid isPermaLink="true">https://dev.connect.gt/post/1083698</guid><dc:creator><![CDATA[eugene]]></dc:creator><pubDate>Wed, 29 Aug 2012 10:38:02 GMT</pubDate></item><item><title><![CDATA[Reply to child theme: errore fatale con funzioni on Tue, 28 Aug 2012 17:47:33 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto"><strong>Eugene</strong></p>
<p dir="auto">Insomma, in questo caso non si può fare a meno di intervenire direttamente nel tema principale.</p>
</blockquote>
<p dir="auto">Veramente io ho capito un' altra cosa, come in questo caso in cui la funzione non è pluggable nel file function di twentyten</p>
<pre><code class="language-php">function twentyten_excerpt_length( $length ) {    return 40;}add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
</code></pre>
<p dir="auto">Se voglio che la lunghezza dell' inizio post sia lunga 55 lettere invece di 40 non basta aggiungere questa mia funzione nel file function del child che non funzionerebbe</p>
<pre><code class="language-php">function my_excerpt_length( $length ) {    return 55;}add_filter( 'excerpt_length', 'my_excerpt_length' );
</code></pre>
<p dir="auto">Ma devo aggiungere anche questa funzione al file function del child che serve a  rimuovere quello di twenty ten in questo modo</p>
<pre><code class="language-php">function my_undo_hooks( $length ) {    remove_filter( 'excerpt_length', 'twentyten_excerpt_length' );}add_action( 'after_setup_theme', 'my_undo_hooks' );
</code></pre>
]]></description><link>https://dev.connect.gt/post/1083696</link><guid isPermaLink="true">https://dev.connect.gt/post/1083696</guid><dc:creator><![CDATA[elmanisero]]></dc:creator><pubDate>Tue, 28 Aug 2012 17:47:33 GMT</pubDate></item><item><title><![CDATA[Reply to child theme: errore fatale con funzioni on Tue, 28 Aug 2012 15:50:31 GMT]]></title><description><![CDATA[<p dir="auto">Grazie mille ancora una volta.<br />
E' tutto spiegato più o meno qui:</p>
<blockquote>
<p dir="auto"><strong>Overriding Functions</strong></p>
<p dir="auto">One exception to the overriding mechanism of child themes has to do  with the functions.php file. In a child theme situation, both  functions.php files from both themes are loaded. This is necessary  because elements of your parent theme might require pieces of the  functions.php file to be loaded. This can make overriding functions in  the parent theme tricky unless it?s written to allow you to do just  that.<br />
The key to this is that the functions.php file of the child theme is  loaded first. So if the parent theme is written in a manner WordPress  calls ?<a href="http://codex.wordpress.org/Pluggable_Functions" rel="nofollow ugc">pluggable</a>?,  then you can override those functions.<br />
In the twentyten theme?s functions.php file, several of the functions  are defined like this:</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>1</th>
<th>if ( ! function_exists( 'twentyten_admin_header_style' ) ) :</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>2</th>
<th>function twentyten_admin_header_style() {</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>3</th>
<th>...</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>4</th>
<th>}</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>5</th>
<th>endif;</th>
</tr>
</thead>
</table>
<p dir="auto">That is a pluggable function. Basically, before it defines the  function, it checks to see if the function is already defined. If the  parent theme uses this mechanism, then a child theme can override this  function by simply defining a function of the same name first. So all  you have to do to change it is to copy the function into your child?s  functions.php file and make your changes. When the parent theme loads,  it will see that you already defined the function and continue on.<br />
Another way to override things is through the normal WordPress action  and filter hook mechanisms. If a theme?s functions.php file uses those,  then you can simply add your own hooked functions with different names.  However, because the child?s functions.php file loads first, it can?t  actually unhook things defined by the parent theme.<br />
The way to get around this is to use the after_setup_theme action  hook. This action is called immediately after both functions.php files  are loaded.<br />
For example, if I look at the twentyten theme, I?ll find this:</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>1</th>
<th>function twentyten_excerpt_length(  $length ) {</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>2</th>
<th>return 40;</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>3</th>
<th>}</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>4</th>
<th>add_filter( 'excerpt_length', 'twentyten_excerpt_length' );</th>
</tr>
</thead>
</table>
<p dir="auto">I don?t want that, I want my excerpts to be 55 words instead. So I  add this to my functions.php file:</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>1</th>
<th>function my_excerpt_length( $length ) {</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>2</th>
<th>return 55;</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>3</th>
<th>}</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>4</th>
<th>add_filter( 'excerpt_length', 'my_excerpt_length' );</th>
</tr>
</thead>
</table>
<p dir="auto">Whoops! It doesn?t work. Why not? Because I didn?t remove twentyten?s  hook, and its filter is overriding mine. So I have to add this too:</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>1</th>
<th>function my_undo_hooks( $length ) {</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>2</th>
<th>remove_filter(  'excerpt_length', 'twentyten_excerpt_length'  );</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>3</th>
<th>}</th>
</tr>
</thead>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>4</th>
<th>add_action( 'after_setup_theme', 'my_undo_hooks' );</th>
</tr>
</thead>
</table>
<p dir="auto">And then it works. I?ve added my filter, and removed the one in  twentyten. Voila.</p>
</blockquote>
<p dir="auto">In breve, il documento <strong>functions.php</strong> del <em>child theme</em> viene caricato prima di quello del <em>main theme</em>. Il codice prevede due tipi di funzioni, quelle "aggiornabili" (<em>pluggable</em>) e quelle no.<br />
Se una funzione è "<em>pluggable</em>" è reso evidente dalla presenza della verifica relativa all'esistenza stessa della funzione <em>in questione</em> <em>(if ( !  function_exists( 'nome_funzione'  ) ) <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=2190ae3dadd" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></em>. In questo caso è possibile scrivere nel nostro <strong>functions.php</strong> la stessa funzione con le modifiche opportune e queste diverranno effettive.</p>
<p dir="auto">Diversamente la funzione non è modificabile attraverso il <em>child theme</em>. Per quel che ho dedotto si deve intervenire direttamente nel <em>main theme</em> modificando la funzione in questione oppure convertendola in "<em>pluggable"</em> per poi modificarla nel <em>child theme</em>.<br />
Insomma, in questo caso non si può fare a meno di intervenire direttamente nel tema principale.</p>
]]></description><link>https://dev.connect.gt/post/1083699</link><guid isPermaLink="true">https://dev.connect.gt/post/1083699</guid><dc:creator><![CDATA[eugene]]></dc:creator><pubDate>Tue, 28 Aug 2012 15:50:31 GMT</pubDate></item><item><title><![CDATA[Reply to child theme: errore fatale con funzioni on Mon, 27 Aug 2012 19:58:14 GMT]]></title><description><![CDATA[<p dir="auto">È possibile modificare alcune cose nel functions.php del tema child, utilizzando filtri, azioni, ecc ma pare che non si possano copiare e modificare se non a certe condizioni alcune funzioni del functions.php di TwentyTen, così almeno mi pare di aver capito nei link qui sotto.<br />
<a href="http://core.trac.wordpress.org/ticket/16500" rel="nofollow ugc">http://core.trac.wordpress.org/ticket/16500</a><a href="http://ottopress.com/2010/wordpress-protip-child-themes/" rel="nofollow ugc">http://ottopress.com/2010/wordpress-protip-child-themes/</a></p>
]]></description><link>https://dev.connect.gt/post/1083695</link><guid isPermaLink="true">https://dev.connect.gt/post/1083695</guid><dc:creator><![CDATA[elmanisero]]></dc:creator><pubDate>Mon, 27 Aug 2012 19:58:14 GMT</pubDate></item></channel></rss>