How can refer a theme from other folder and make directory path to other theme in Wordpress - wordpress

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.

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

Can I set wordpress theme via code

I have been working on wordpress for a while. I know that we can manage themes via the admin panel and the selected theme and its configuration details are stored in the database.
Is there any way I can set the theme via my wordpress code?
Have a look at the switch_theme function on the Codex
Description
Switches current theme to new template and stylesheet names.
Accepts one argument: $stylesheet of the theme. ($stylesheet is the name of your folder slug. It's the same value that you'd use for a child theme, something like twentythirteen.) It also accepts an additional function signature of two arguments: $template then $stylesheet. This is for backwards compatibility.
Usage
<?php switch_theme( $stylesheet ) ?>

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

Using Jetpack Portfolio Project in WordPress child theme does not call archive custom template

I have a child theme that uses the new Jetpack Portfolio Project custom post type and wish to modify archive.php to display custom results.
I'm using: WordPress v3.9.2; Theme: Child of Point, Jetpack is installed with Custom Content Types enabled, and Portfolio Projects selected in the Settings. (No other plugins that implement portfolio functionality are installed.)
According to the Codex:
Template Files
In the same way single posts and their archives can be displayed using
the single.php and archive.php template files, respectively,
single posts of a custom post type will use single-{post_type}.php
and their archives will use archive-{post_type}.php
and if you don't have this post type archive page you can pass BLOG_URL?post_type={post_type}
where {post_type} is the $post_type argument of the
register_post_type() function.
My understanding is that if you create files called single-jetpack-portfolio.php and archive-jetpack-portfolio.php within the child theme, WordPress will automatically use those files in place of single.php and archive.php respectively.
However, my child theme successfully calls single-jetpack-portfolio.php, but completely ignores archive-jetpack-portfolio.php, instead calling archive.php in the child.
I am stuck for a solution.
From the codex above, adding to the URL "?post_type=jetpack-portfolio" does cause the child theme to correctly use archive-jetpack-portfolio.php, but should I need to be manually modifying every single URL to explicitly specify this? Should WordPress not automatically be detecting this, as it does for the single-jetpack-portfolio.php file? How can I solve this?
I have tried:
Resetting the permalinks in case it was related to that (changing the option in Settings and saving and back again)
Adding an archive.php file to the child in addition to archive-jetpack-portfolio.php (I initially didn't have an archive.php in the child, so it used the parent's archive.php)
Publishing a new Jetpack portfolio project and updating an existing page (I read somewhere that publishing something might trigger Wordpress to see the changes)
Thanks in advance for any help.
I had the same problem described by the OP. When I visited mydomain.com/portfolio it would use the custom archive template. When I tried to view a project type it defaulted to the regular archive.php. I'm wondering if OP was viewing a project type page without realizing it.
My solution was to create a taxonomy template file. After playing around with it I figured out that
taxonomy.php
taxonomy-jetpack-portfolio-type.php
taxonomy-jetpack-portfolio-type-{name-of-project-type}.php
all worked correctly, depending on how specific you wanted to get.
There's more info at the wordpress codex: http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display
Hope this helps someone.
I will be working on this the next days.
You should try this in the child archive.php first lines:
<?php
if( is_post_type_archive('jetpack-portfolio') )
get_template_part('content', 'jetpack-portfolio');
elseif( is_tax('jetpack-portfolio-type') || is_tax('jetpack-portfolio-tag') )
get_template_part('archive', 'jetpack-portfolio');
else continue;
?>

Resources