8721 sujets

Développement web côté serveur, CMS

Bonjour,

Je poste ce message car je bloque sur un point.

Je souhaite créer un thème enfant WordPress. La méthode pour y parvenir est facilement trouvable sur Internet et peu difficile à mettre en place.

- Créer un dossier dans lequel seront présents un fichier style.css et un fichier functions.php

- Style.css :

/*
Theme Name: Theme enfant
Description: Theme enfant de XXX
Author: XXX
Author URI:  https://www.xxx.fr
 
Template: themeparent 
Version: 0.1.0
*/

.navbar {
	background-color: red;
	position: fixed;
	top: 0;
	right: 0;
	left: 0;
	z-index: 999;
}


- functions.php :


<?php
/**
** activation theme
**/
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
 wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}


Toutefois, ce code PHP ne me permet pas de personnaliser mon thème enfant. Les instructions CSS (dans le fichier style.css créé plus haut) ne sont pas prises en compte.

En revanche, lorsque je saisis ce code PHP (généré par un générateur de thème enfant (extension WordPress), ça fonctionne :


<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:

if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
    function chld_thm_cfg_locale_css( $uri ){
        if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )
            $uri = get_template_directory_uri() . '/rtl.css';
        return $uri;
    }
endif;
add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );
         
if ( !function_exists( 'child_theme_configurator_css' ) ):
    function child_theme_configurator_css() {
        wp_enqueue_style( 'chld_thm_cfg_child', trailingslashit( get_stylesheet_directory_uri() ) . 'style.css', array( 'style','style','bootstrap-css','custom-css','flexslider-css','font-awesome-css' ) );
    }
endif;
add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css', 20 );

// END ENQUEUE PARENT ACTION



Sauriez-vous me dire pourquoi le premier code PHP ne fonctionne pas ?

Merci de votre aide Smiley smile
Modifié par MickFR (06 Feb 2019 - 10:01)
Bonjour,
Je vois que dans ton code php tu as laisser 'parent-style'


 wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );


Le ' parent-style' est à remplacer par le nom du thème parent.

Exemple :
Si ton thème parent est le thème virtue de WordPress alors la ligne devra être :

wp_enqueue_style( 'virtue', get_template_directory_uri() . '/style.css' );
Merci de ta réponse.

Je viens de modifier le fichier functions.php.
J'ai remplacé
'parent-style'
par
'busiprof'

busiprof est le nom du thème parent.

Toutefois, les instructions CSS ne sont pas prises en compte.

Lorsque j'active le thème enfant, il s'affiche (à l'identique de son parent) sans les surcharges CSS.

Ça fonctionne très bien en utilisant un générateur de thème enfant mais la manipulation "manuelle" est simple. J'aimerais réussir à le faire sans passer par un générateur.
Lors de la création de ton fichier style.css as-tu bien mis les informations dans l'entête ?

Quelque chose ressemblant à cela pour toi :


/*
Theme Name: Un beau theme
Description: Ton theme enfant
Author: Toi
Template: busiprof
Version: 1.0
*/
L'entête du fichier CSS contient ça :


/*
Theme Name: busiprof-child
Description: Busiprof WordPress Theme is a fully responsive and translation-ready theme that allows you to create stunning blogs and websites. The theme is well suited for companies, law firms,ecommerce, finance, agency, travel, photography, recipes, design, arts, personal and any other creative websites and blogs. The theme is developed using Bootstrap 3 that makes it mobile and tablet friendly. It has various options in the WordPress Customizer to change the look of the theme. The theme customizer can be used to add your own favicon, logo, feature slide, services, 2 testimonial slider, blog, callout and much more. In the premium version you can add unlimited slides. There are a number of in-built widgets and support for various popular plugins like WPML, the Polylang Translation WordPress Plugin, Woocommerce and Contact Form 7. 10 beautifully designed templates like About Us, Services, Portfolio 2/3/4 column, Portfolio with Category, Portfolio Archive, Blog Left/Right Sidebar, Blog Fullwidth, Full Width Page, Contact Us and many useful sections for business using the Homepage template. Busiprof theme comes with various Locales. Just navigate to Appearance / Customize to start customizing.
Author: MickFR
Template: busiprof
Version: 1.0
*/


Lorsque le générateur génère le thème enfant, le fichier functions.php contient plus d'informations. Je vois qu'il fait mention de 'custom-css','flexslider-css' etc. Ça vient peut être de là...
Dans le fichier style.css (dans le dossier enfant busiprof-child), j'ai bien cet en-tête :


/*
Theme Name: busiprof-child
Description: Busiprof WordPress Theme is a fully responsive and translation-ready theme that allows you to create stunning blogs and websites. The theme is well suited for companies, law firms,ecommerce, finance, agency, travel, photography, recipes, design, arts, personal and any other creative websites and blogs. The theme is developed using Bootstrap 3 that makes it mobile and tablet friendly. It has various options in the WordPress Customizer to change the look of the theme. The theme customizer can be used to add your own favicon, logo, feature slide, services, 2 testimonial slider, blog, callout and much more. In the premium version you can add unlimited slides. There are a number of in-built widgets and support for various popular plugins like WPML, the Polylang Translation WordPress Plugin, Woocommerce and Contact Form 7. 10 beautifully designed templates like About Us, Services, Portfolio 2/3/4 column, Portfolio with Category, Portfolio Archive, Blog Left/Right Sidebar, Blog Fullwidth, Full Width Page, Contact Us and many useful sections for business using the Homepage template. Busiprof theme comes with various Locales. Just navigate to Appearance / Customize to start customizing.
Author: MickFR
Template: busiprof
Version: 1.0
*/

Modifié par MickFR (06 Feb 2019 - 17:12)
Je dois bien t'avouer que je ne comprends pas trop d'où vient le problème pour le coup.
Pour moi tout tes fichiers sont bien mis et tout est correct à l'intérieur de ceci.

Question bête :
Active-tu ton thème enfant à toi dans l'admin de WordPress ?
Salut,

Désolé de répondre avec retard.
J'ai changé de thème et ça fonctionne.

Je n'ai pas réussi à trouver d'où venait le problème avec le thème précédent (il était bien activé).

Merci de ton aide Smiley smile