Load CSS Wordpress Theme - wordpress

I'm trying to load in my css for a WordPress theme however it doesn't seem to load.
Here is what I have so far
I am new to building WordPress themes so any help is great.

Your main style.css file needs to be in the root folder. Move style.css from the css folder to the root folder (same folder as index.php).

Custom Theme need two files
i)style.css
ii)functions.php
you can call your style sheet from functions.php using hooks
ex:
function wpdocs_theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri().'yourstylesheetname.css' );
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );

There are some Required Theme Files that you have to add in your theme folder in order to start
You have at least to have these two files: style.css & index.php
I see that you have an index.php thats's good, but for the style.css file in yourThemeFolder/css folder, hasn't been recognized by wordpress, because In order for WordPress to recognize the set of theme template files as a valid theme, the style.css file needs to be located in the root directory of your theme, not a subdirectory, (the same directory of you index.php file).
Take a look at Required Theme Files or Main Stylesheet CSS for more Information.

Related

Can not translate my wordpress website - no .pot file

I could not find a .pot file so I created one with Eazypo. There was no languages folder in the theme folder either. I created a "languages" folder and uploaded the newly created .pot file. I translated every string and uploaded the new .mo and .po files in the "languages" folder and I defined wp lang to have the value of the .mo file name. Not working.
Any ideas of what can be wrong or how to solve this issue?
Thank you
In order for your theme to load your translation files, you need to use the load_theme_textdomain() function.
Add the following code to your theme's functions.php file:
function wp756531_my_theme_setup(){
load_theme_textdomain( 'my-theme', get_template_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'wp756531_my_theme_setup' );
Important Notes:
Make sure to change the 'my-theme' domain to the one your theme uses.
Make sure your translation files are named after your locale(s) (eg. es_ES.mo, sv_SE.mo, etc)

Language file not loading - Wordpress Child Theme

I'm trying to add a Dutch translation to a Wordpress theme.
I have edited .pot file (inside the theme) with POedit, and saved nl_NL .po and .mo (without any issues).
Naturally, I've made languages directory in my childtheme (called charityhub-child).
I have changed my code in the most basic form (taken from Wordpress Code reference).
My functions.php looks like this:
function wpdocs_child_theme_setup() {
load_child_theme_textdomain( 'charityhub', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'wpdocs_child_theme_setup' );
Parent theme name = charityhub.
What seems to be the problem here ? Language files are not loading...

What's the difference between get_stylesheet_directory_uri() and get_template_directory_uri() when enqueuing scripts in wordpress

It's not a serious question.
I normally use get_stylesheet_directory_uri() when enqueuing scripts in WordPress, which worked fine so far.
I just wonder what's the difference between get_stylesheet_directory_uri() and get_template_directory_uri() when enqueuing scripts in wordpress.
According to WordPress Codex:
get_template_directory_uri -> Retrieve template directory URI for the
current theme.
get_stylesheet_directory_uri ->Retrieve stylesheet directory URI for
the current theme/child theme
Then, get_template_directory_uri cannot be used for a child theme?
Both functions can be used in a parent or a child theme.
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).
For example, in a child theme:
// This will point to style.css in child theme
wp_enqueue_style( 'my_child_styles', get_stylesheet_directory_uri().'/style.css' );
// This will point to style.css in the parent theme
wp_enqueue_style( 'my_parent_styles', get_template_directory_uri().'/style.css' );
Note that if a theme is not a child theme, then it is considered a parent theme.

Why is my localization in wordpress not working?

I have created a theme.
All words and phrases are using either:
__('Word Here','mythemelocalpath')
or
_e('Word Here','mythemelocalpath')
I have made a folder called languages within the my new themes folder.
I created a .mo and .po and .pot file with poedit and placed them within the languages folder which is within my new theme folder.
The .mo, .po, .pot files are after the localization which is example: de_DE.mo
I then wrote this bit of code within the functions.php:
function mycustom_load_localization() {
// Retrieve the directory for the localization files
load_theme_textdomain( 'mythemelocalpath', TEMPPATH.'/languages' );
} // end custom_theme_setup
add_action('after_setup_theme', 'mycustom_load_localization');
I then enter the wp-config.php file and change the WP_LANG to de_DE
But for some reason its not working?
Can someone shed some light on this.
Thanks :)
Try this
load_theme_textdomain( 'mythemelocalpath', get_stylesheet_directory() . '/languages/' );
instead of
load_theme_textdomain( 'mythemelocalpath', TEMPPATH.'/languages' );
where get_stylesheet_directory() should give you the stylesheet directory path and it should be child theme save ;-)
Reference:
http://codex.wordpress.org/Function_Reference/get_stylesheet_directory

style.css in css directory (i.e. not in theme root)

I'm new to WordPress and this is my first attempt to migrate a static website to WordPress. The websites layout must remain unchanged so I intend to develop a theme for it.
I'm used to having css files in the css directory, but the WordPress Theme Development page states that there has to be a style.css in the theme root.
Can I setup WP to get css/style.css instead? What is the recommended way to organise css files in WP?
You can use Wordpress' wp_enqueue_style.
function addMyScript() {
wp_enqueue_style( 'my-style', get_template_directory_uri() . '/css/my-style.css', false, '1.0', 'all' );
}
add_action('wp_head', 'addMyScript');
Just remember that you still need to have a style.css inside your theme root, even if it only has the details about the Theme in the form of comments.
Please refer to: http://codex.wordpress.org/Function_Reference/wp_enqueue_style

Resources