Replacing Woocommerce Storefront header with a shortcode - php

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"]')
}

Related

Execute a shortcode inside a folder in a Child Theme

I'm confused on how to run my custom shortcode in my child theme. To my understanding, I should be only including/requiring the file in the functions.php in my child theme right?
My File Structure is like this
**Child Theme**
-functions.php
-deals
--deals.php
In my functions.php i just place the code
require_once('deals/deals.php' );
And in my deals.php, I have this shortcode
add_shortcode('show-deals','show_deals');
function show_deals() {
return 'Show Deals';
}
So it doesn't get rendered. Help

Trying to overwrite / append editor-style.css from parent theme in child theme

I am using the good old twenty eleven for a simple job and overwrite styles using a child.
The Problem is, that editor styles are not overwritten when i add an editor-child.css in the child theme folder.
Adding add_editor_style in the child themes functions.php (wrapped in after_setup_theme) doesn't seem to work. Can't I load multiple editor styles or what is the problem here? I can't figure out how I can overwrite this ugly twenty eleven editor css in gutenberg. It might even be better to disable it, but even that doesn't work using remove_editor_style. And I can't find anything on the subject using google or stackoverflow.
<?php
// In the child theme functions.php. I simply want to use the style.css by the child theme as an extra editor style
function wysiwyg_styles() {
add_editor_style( get_stylesheet_uri() );
}
add_action( 'after_setup_theme', 'wysiwyg_styles');
?>
No css is loaded in the admin (after deleting chache AND cookies)
What happen is that you're using the wrong action hook... you should be using the admin_enqueue_scripts hook.
Try doing it like this.. and check if it works for you:
add_action('admin_enqueue_scripts', function () {
wp_enqueue_style('admin-styles', get_stylesheet_directory_uri().'/pathToYour.css');
});
// If the above does not work change get_stylesheet_directory_uri() for get_template_directory_uri()
Hope this can help, good luck.
You can try instead:
add_theme_support( 'editor-styles' );
add_editor_style( 'style-editor.css' );
in your functions.php. Haven’t checked if it works with a child theme though.
More information here:
https://developer.wordpress.org/block-editor/developers/themes/theme-support/

How to place content from function in My Account in Woocommerce?

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

wordpress-add codes to function.php

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

Custom excerpt for child template on Wordpress

I've been creating a child Wordrpess theme. The parent theme is TwentyTwelve theme.
I override styles.css file and it works perfectly. But I can't replace the_excerpt function on my functions.php
I've been searching but I can't find the solution.
functions.php
<?php
function custom_excerpt($text) {
return "Test";
}
function my_child_theme_setup() {
add_filter('the_excerpt', 'custom_excerpt');
add_filter('get_the_excerpt', 'custom_excerpt');
add_filter('default_excerpt', 'custom_excerpt');
}
add_action( 'after_setup_theme', 'my_child_theme_setup' );
?>
I just wan't to show the featured image on the excerpt linking the original post.
Thanks!

Categories