How to make get_header() call a custom header file located in a sub-folder of the theme? - wordpress

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/

Related

Wordpress child theme translation

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

Require another file before require file functions.php Wordpress

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

Wordpress Mezzanine Flat Theme - shortcode.php in ChildTheme

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'; )

Overwriting parent's theme files in Wordpress

It seems like my Wordpress child theme in some cases refuses to use child files and still uses parent's files.
For example I want to override the themex.lesson that is located in the
child_theme/framework/classes/themex.lesson.php folder
Parent's file is in the:
parent/framework/classes/themex.lesson.php folder
Changes that I make to the child_theme themex.lesson php are not reflected in live site. Other changes made to the child theme work perfectly fine.
What could be causing this behavior?
Referencing / Including Files in Your Child Theme
When you need to include files that reside within your child theme's
directory structure, you will use get_stylesheet_directory(). Because
the parent template's style.css is replaced by your child theme's
style.css, and your style.css resides in the root of your child
theme's subdirectory, get_stylesheet_directory() points to your child
theme's directory (not the parent theme's directory).
Here's an example, using require_once, that shows how you can use
get_stylesheet_directory when referencing a file stored within your
child theme's directory structure.\
require_once( get_stylesheet_directory() . '/my_included_file.php' );
Source: https://codex.wordpress.org/Child_Themes

Wordpress, Gantry Framework, Child Theme?

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.

Resources