I'm really really stuck here so I'd appreciate some help from above...
I'm using the jkreativ theme and am currently trying to translate my child-theme.
I am using this code in my childthemes functions.php:
<?php
/**
* Setup My Child Theme's textdomain.
*
* Declare textdomain for this child theme.
* Translations can be filed in the /languages/ directory.
*/
function my_child_theme_setup() {
load_child_theme_textdomain( 'jkreativ-child', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'my_child_theme_setup' );
?>
In my Childthemes Folder I have a folder called "languages" that contains the
de_DE.mo
de_De.po
files.
I looked in the wordpress codex and to me this seems to be the proper way.
But no single line gets translated...
Any ideas anyone?
Thanks!
Paul
There is a post at wordpress.stackoverflow.com with this problem. Basically what you have to do is
Create a folder inside your languages one with the name of your parent theme;
Place there the .mo file that will overwrite the parent theme translations;
Change your code like this:
function my_child_theme_setup() {
load_theme_textdomain( 'jkreativ', get_stylesheet_directory() . '/languages/jkreativ' );
load_child_theme_textdomain( 'jkreativ-child', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'my_child_theme_setup' );
Calling load_theme_textdomain and passing the parent theme domain will do the trick.
Hope it helps!
Related
I'm trying to make my wordpress site translation ready, using 'poedit'. I have problems with activating the translation. I want to translate the site only, not wordpress system. I have my .pot, .po and .mo files in a 'languages' folder in my theme directory, I have this code in my functions.php file:
load_theme_textdomain( 'example', get_template_directory() . '/languages' );
well, after everything is saved and translated in the poedit program, how do I activate it in my site? I am working with a localhost for now.
First, you need to connect the method to an action hook in your theme functions.php:
function load_mytheme_textdomain() {
load_theme_textdomain( 'example', get_template_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'load_mytheme_textdomain' );
Then you have to use translation instead of echo for output:
_e( 'My Text', 'example' );
Read more here: https://developer.wordpress.org/themes/functionality/internationalization/
I actually am a newbie to wordpress, i am converting an html website to wordpress template. There are alot of js file in my js directory but all of them are not loaded on every page. What I want to know is that do we have to register all js files in functions.php and use wp_head in our head tag to load them?
For theme you need to put below code in your functions.php
function wpb_adding_scripts() {
wp_register_script('my_amazing_script', get_template_directory_uri() . '/js/amazing_script.js', array('jquery'),'1.1', true);
wp_enqueue_script('my_amazing_script');
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' )
If you are creating your custom plugin below code will help you.
function wpb_adding_scripts() {
wp_register_script('my_amazing_script', plugins_url('amazing_script.js', __FILE__), array('jquery'),'1.1', true);
wp_enqueue_script('my_amazing_script');
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
For more understanding of wp_enqueue_script read below two links :
https://developer.wordpress.org/reference/functions/wp_enqueue_script/
http://www.wpbeginner.com/wp-tutorials/how-to-properly-add-javascripts-and-styles-in-wordpress/
As you are beginner i can say wpbeginner will be good site for you they give the all understanding very clearly
I am pretty new to WordPress development. I read that it's better to use wp_enqueue_style and do_action inside the functions.php file rather than linking CSS files directly as I would when not using WordPress.
Why this is a best practice? What are its advantages?
If you have activated child theme then use get_template_directory_uri() functions.
If you have activated parent theme then use get_stylesheet_directory_uri() functions.
get_template_directory_uri will always refer to the parent theme folder for assets.
get_stylesheet_directory_uri will refer to the "current" theme folder for assets (which could be the parent or the child, depending on where it is called).
Child theme example:
wp_enqueue_style( 'my_child_styles', get_stylesheet_directory_uri().'/style.css' );
Parent theme Example
wp_enqueue_style( 'my_parent_styles', get_template_directory_uri().'/style.css' );
Method-1
// load css into the website's front-end
function mytheme_enqueue_style() {
wp_enqueue_style( 'mytheme-style', get_stylesheet_directory_uri().'/style.css' );
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_style' );
Method-2
// Add this code in your functions.php
function add_stylesheet_to_head() {
echo "<link href='".get_stylesheet_directory_uri()."/style.css' rel='stylesheet' type='text/css'>";
}
add_action( 'wp_head', 'add_stylesheet_to_head' );
Because wp-enqueue-style adds scripts/styles to the queue.
Registers the style if source provided (does NOT overwrite) and enqueues.
In wordpress I have created a child theme and for some template made changes according to design in style.css in child theme.
I have also created a new template in child theme but I want that the style.css which in child theme not added with the only one template on frontend. my template file name is template-custom.php.
How to do that?
You can use wp_dequeue_style function to remove css on specific template
Try below code it will work :
/**
* Remove specific style sheets.
*/
function some_remove_styles() {
if ( is_page_template( 'yourtemplate.php' ) ) {
wp_dequeue_style( 'some-style' );
wp_dequeue_style( 'some-other-style' );
}
}
add_action( 'wp_print_styles', 'some_remove_styles', 99 );
I've been trying with no success to add a new stylesheet to my template. It's my first time creating a wordpress template. I'm using underscore and this is what I have in functions.php:
style.css is the stylesheet shipped with the template starter.
wp_enqueue_style( 'name-style', get_stylesheet_uri() );
I just want to add foundation-icons.css, foundation.min.css and custom.css. Any help? Thanks.
This is how I do it in all of my templates
/* Enqueue Scripts
-----------------------------------------------------------------*/
add_action( 'wp_enqueue_scripts', 'template_enqueue_scripts' );
function template_enqueue_scripts() {
wp_register_style('Sub-CSS', get_template_directory_uri() .'sub-style.css');
wp_enqueue_style( 'Sub-CSS');
}
This is the best way to my knowledge, like I said, I always do it this way. It works flawlessly, and I have never had a problem doing it this way.
Edit
You will notice that no one else uses wp_register_style, and the wp_register_style is the safest way to setup your style for actual enqueue.
Make sure that you wrap the wp_register_style & wp_enqueue_style in a function.
Try this code :
<?php
add_action( 'wp_enqueue_scripts', 'safely_add_stylesheet' );
/**
* Add stylesheet to the page
*/
function safely_add_stylesheet() {
wp_enqueue_style( 'prefix-style', plugins_url('style.css', __FILE__) );
}
?>