i want to create my first theme. i added my codes in header.php and function.php but my theme doesn't know i added function.php to my theme at all!
here the codes in function.php:
<?php
DEFINE("THEME_LOC",get_template_directory_uri() );
remove_action('wp_head','wp_generator');
function enq_style(){
wp_register_style('style',THEME_LOC.'/style.css',array(),'1','all',false);
wp_enqueue_style('style');
}
add_action('wp_enqueue_scripts','enq_style');
?>
when i call THEME_LOC from header.php. it doesn't know i stored my theme location into this constant.
what's the problem?
shall i include my function.php into my theme or something?
i've got another question too.
does style.css add to my theme automatically or i have to register that style to my theme like what i did in fucntion.php?
It should be:
define( "THEME_LOC", get_template_directory_uri() );
Related
I've added a custom JQuery script to a new JS file "themes\twentytwentyone\js\script_new.js".
And I load this new JS file in theme functions.php file.
function add_custom_script() {
wp_enqueue_script(
'my_script',
get_stylesheet_directory_uri() .'/js/script_new.js',
array( 'jquery' ),
'1.0',
true
);
}
add_action( 'wp_enqueue_scripts', 'add_custom_script' );
This works without any issue. But is there a way to achieve this without updating the theme functions.php file?
I'm not sure if updating the functions.php file is good practice.
Using child's theme functions.php is the best practice .
But if you don't want to use functions.php then you can call js file through footer.php or header.php too.
Please note i recommend and it is the safest to make child theme for any customisation and use Child theme's functions.php.
I am creating custom WordPress theme. I have a child theme and parent theme.
One issue is my child theme function.php file not adding bootstrap files, So I called it in parent theme, but now the issue I am getting is bootstrap CSS taking priority over my child style.css.
I have tried this code in my child theme function.php file but its not working.
Its not showing any custom.css in view source. I have both files in correct path
add_action('wp_enqueue_scripts', 'theme_enqueue_styles', 100);
function theme_enqueue_styles()
{ $parent_style = 'flambird-style';
$child_style = array('flambird-style');
wp_enqueue_style($parent_style, get_template_directory_uri() . '/bootstrap/custom.css', array());
wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/css/custom.css', $child_style);
}
its not adding custom in both condition. I think my child theme function.php file is not working.
Please help me on this. I want to use child theme css file.
enter image description here
Add !important to your css formats when there is a conflict, or host your own copy of Bootstrap with compatible changes.
I am using Woocommerce Storefront theme and I want to replace the original header with a custom header that I created in elementor. I have a shortcode for the new header but I don't know how to insert it into the code. I am using a blank storefront child theme and there is a function.php file and style.css file.
Thanks for the help.
Just copy the header.php from the parent theme and paste it inside the child theme. Then you can already put your custom code in it.
Reference: codex.wordpress.org/Child_Themes
You can do this in your child theme by using a hook on init
Something like this:
add_action('init', 'replace_header' );
function replace_header(){
remove_action( 'storefront_header', 'storefront_primary_navigation', 50 );
add_action('storefront_header', 'my_custom_header', 50);
}
function my_custom_header(){
do_shortecode('[your_elementor_header_shortcode attr1="value1"]')
}
Hi i have this function inserted into functions.php in my theme:
function woocommerce_after_account_navigation(){
$html = '<h3>Title</h3>';
$html.='<li>Text1</li>';
$html.='<li>Text2</li>';
echo $html;
}
and have placed this hook into navigation.php file from WooCommerce templates
<?php do_action( 'woocommerce_after_account_navigation' ); ?>
but seems that dont show nothing from content that i placed into functions.php
Can someone help me what is wrong with this hook ?
Youn don't need to change anything in the My account templates (as you are using an existing hook)… To get your custom content displayed, you should need to make it this way:
add_action( 'woocommerce_after_account_navigation', 'custom_content_after_account_navigation' );
function custom_content_after_account_navigation(){
$html = '<h3>Title</h3>';
$html.='<li>Text1</li>';
$html.='<li>Text2</li>';
echo $html;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested on WooCommerce 3 and works.
This custom content will be displayed below the My Account Menu
I am developing a plugin that needs to overwrite the hook to the parent style.css.
I use the plugin to dequeue the style from the child theme but then I need to enqueue another file into it so that the child theme css works. Not sure if I am making sense.
Basically how would I go about adding this code into the child theme functions.php via my plugin:
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'child-style', plugins_url( '/plugin/css/3.0.31' ) . '/style.min.css' );
}
As it is a plugin it would need to do it automatically without access to the file.
Any ideas?
Thanks