I'd like to translate a child theme of wordpress twentythirteen theme.
Following the documentation, I've created and located fr_FR.po and fr_FR.mo files in a languages subdirectory of the child theme. The translation files contain only the child theme's specific translations. Then I've added the following in functions.php:
function theme_vja_setup() {
load_child_theme_textdomain('twentythirteen',
get_stylesheet_directory()."/languages");
}
add_action('after_setup_theme','theme_vja_setup');
I can't get what I'm doing wrong but I can't get the child theme translated
Looking at wordpress trac:
load_child_theme _text_domain verifies that $path is not empty and then call load_theme_text_domain.
load_theme_text_domain in turn tries to load the parent localization file wp-content/languages/themes/twentythirteen-fr_FR.mo which exists --> the function load_text_domain returns true and the loading stops
Any direction would be appreciated, I'm going crazy.
You don’t need this code in functions.php. Copy the .po and .mo files in the wp-content/languages/themes folder.
Name them:
[yourchildthemename]-fr_FR.po
and
[yourchildthemename]-fr_FR.mo.
(replace [yourchildthemename] by the slug of your child theme)
Regards Tom
Related
From a PHP template file located in a sub-folder of my WP theme folder (my_theme/subfolder/my_file.php) I want to use get_header() and call a custom header-new.php located in the same sub-folder.
Instead, get_header(header-new) loads header.php located in my theme root folder. How to fix that problem?
You are correct to use get_header() function. However, as per documentation you should pass the name of the custom header in the specific format - only the part that comes between 'header-' and '.php'. E.g. for the custom header in the file:
header-custom.php
you should use:
get_header('custom');
But that's not all. It is important to remember that the custom header file should be placed in 1 or 2 specific directories, depending on whether you're working on parent or child theme:
Parent theme: you should place it either in the same directory as the page template or the 'root' theme directory (specifically the same directory where your style.css is)
Child theme: you have to place it in the 'root' child theme directory
get_header() function calls locate_template() function, which searches for the custom header file in those 2 directories. If it doesn't find the file, it defaults to 'header.php'.
you can use :
get_template_part('header-new.php');
reference here: >https://developer.wordpress.org/reference/functions/get_template_part/
I'm new in Wordpress and i have few qustions. I research on the internet, but i don't find the proper answer.
Firstly, exist one way to get URL to reference theme?
And the second questions, how can make a directory path to reference theme?
Thanks for answer and help!
Template URI
To get the current active theme's directory URI, use get_template_directory_uri(). For example:
<?php
$directory_uri = get_template_directory_uri();
$my_file = $directory_uri . '/images/path/to/img.jpg';
See official documentation here.
Template PATH
To get current active theme's directory PATH, use get_template_directory().
<?php
$directory_path = get_template_directory();
$my_file = $directory_path . '/images/path/to/img.jpg';
Official documentation here.
Difference between theme and template
Do note that both the function will return URI or path of the active template, meaning, if you use a child theme, then the parent theme's URL or PATH will be returned. If it is not a child theme, then simply the URL or PATH of the current theme will be returned.
If you are using a child theme and want to get the references of current child theme, then use get_stylesheet_directory_uri and get_stylesheet_directory instead.
Getting values for any theme
If your theme is not the active one, then you will need to use get_theme_root_uri and get_theme_root instead.
Same as title, i want require file 'foo.php' before wordpress require 'functions.php' in theme. What's solution? Somebody can help me?
Use a Child Theme.
Basically you just do this:
Create a directory in your themes directory to hold the child theme.
The theme directory is wp-content/themes. You should name the
directory without any space as part of the name, and it is common
practice to use the name of the parent theme folder with “-child”
appended to it. For example, if you are making a child of the
twentyfourteen theme, your folder name would be twentyfourteen-child.
Inside, you can create a functions.php and add the code you want, you can even call other files, like your foo.php:
(...) the functions.php of a child theme does not override its counterpart
from the parent. Instead, it is loaded in addition to the parent’s
functions.php. (Specifically, it is loaded right before the parent’s
file.)
You can also create a plugin, they are loaded before functions.php, you can take a look at the loading order here: https://wordpress.stackexchange.com/questions/26537/between-functions-php-widgets-and-plugins-which-is-loaded-first
It seems that an edited copy of shortcodes.php in child-theme of mezzanine flat theme is not working (does not override the parent theme)
I tried copying the whole lib folder where shortcodes.php is located but still not working. Is there anything I need to do to make it work? Other common pages of wordpress (i.e. header and page) override smoothly on child pages.
Thanks in advance.
You can't override shortcodes.php because the child theme replace only template files
But you can create a new file, like custom_shortcodes.php with your custom shortcode, save in your child theme and then include it in functions.php ( include 'custom_shortcodes.php'; )
Does anyone have experience with Gantry Framework?
I am wondering if it is possible to create a child theme based off of the default? Where would I put my css file and can I build off of the current css instead of starting from scratch while still separating my css from the default theme?
Apart from the usual process of creating a WordPress child theme (create a directory, with proper style.css and functions.php), Gantry requires a specific procedure.
You'll need to copy two files from the parent directory to the child theme directory, keeping the structure:
/gantry/theme.yaml
and
/includes/theme.php
Then, edit the copied theme.yaml: the parent must be your parent theme directory name.
On the theme.php, select all text and replace with this:
// Initialize theme stream.
$gantry['platform']->set(
'streams.gantry-theme.prefixes',
array('' => array(
"gantry-themes://{$gantry['theme.name']}/custom",
"gantry-themes://{$gantry['theme.name']}",
"gantry-themes://{$gantry['theme.name']}/common",
"gantry-themes://{$gantry['theme.parent']}",
"gantry-themes://{$gantry['theme.parent']}/common"
))
);
As for css, you must create this file, within your child theme directory:
/custom/scss/custom.scss
It can be formatted in either SCSS or CSS, and will override the theme's core style sheet files.
Creating a Child Theme is very easy.
All you need to do is create a directory in your theme directory, and name it something like "Gantry-child". Inside that folder, add a file called "style.css". Once this is done, you just need to add the Theme Information that tells Wordpress the Child Theme's Name, Author, and Parent Theme.
Inside the new style.css, add:
/*
Theme Name: Gantry Child
Template: rt_gantry_wp
*/
The most important part that lets Wordpress know that this is a child of the Gantry Theme is the "Template" section. This is the name of the PARENT directory in your Themes folder.
What this will do is create a new theme that inherits all of the parent theme's functions. If you also want to inherit the existing parent theme stylesheet, add to style.css:
#import url("../rt_gantry_wp/style.css");
Hopefully this should get you started. Once that's done, you can add your own header, footer, index, functions, or anything else you can think of to extend the parent theme's functionality.
Hopefully this helps get you started.