Function not showing up in child theme WordPress - php

I was having problems with functions in the Aaron child theme in WordPress. I had part of my problem answered in Overwrite parent functions in child function.php WordPress but I couldn't get the logo to work as a bigger size. I eliminated a lot of code in order to narrow down and find the problem. And what I found is that the function in child theme wasn't showing up in WordPress. This is the function:
/* Site Logo */
function add_site_icon_support() {
$args = array(
'header-text' => array(
'Site Title Here',
'Your site description goes here.',
),
'size' => 'medium',
);
add_theme_support( 'site-logo', $args );
}
add_action( 'after_setup_theme', 'add_site_icon_support' );
I tested it out by adding it to the functions.php in parent theme and it works. Therefore, I was wondering how to make it work in the child theme?
Does it have something to do with this function in parent theme?
function aaron_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on aaron, use a find and replace
* to change 'aaron' to the name of your theme in all the template files
*/
load_theme_textdomain('aaron', get_template_directory() . '/languages');
// Add default posts and comments RSS feed links to head.
add_theme_support('automatic-feed-links');
add_theme_support('woocommerce');
add_theme_support('jetpack-responsive-videos');
add_editor_style();
add_theme_support('post-thumbnails');
add_image_size('aaron-featured-posts-thumb', 360, 300);
add_theme_support('title-tag');
register_nav_menus(array(
'header' => __('Primary Menu', 'aaron'),
'social' => __('Social Menu', 'aaron'),
));
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption'));
}
endif; // aaron_setup
add_action('after_setup_theme', 'aaron_setup');
Since both have the same hooks.

You need to run your hook later than the parent theme. You need to remember, child theme load first, then parent theme.
To make your function work, you need a lower priority, which is a higher number. You can try
add_action( 'after_setup_theme', 'add_site_icon_support', 11 );

Related

Remove downloads metabox in Woocommerce order edit pages

I am trying to remove the 'woocommerce-order-downloads' div in the admin menu from the 'shop_order' context. I got a great answer to identify the context and was able to remove the 'postcustom' div with the following code. Note that I'm trying to the exact same thing by including a line to remove 'woocommerce-order-downloads' as well. That piece is not working. I've tried 'order-downloads', 'downloads', etc. I also went to Settings --> Account --> Blanked our 'downloads' route. This seems odd but I'm relatively new. Any ideas how to remove this pesky div? I'm also trying to remove the order_label div as well... As you can see :)
function remove_custom_field_meta_box()
{
remove_meta_box('postcustom', 'shop_order', 'normal', 90);
remove_meta_box('woocommerce-order-downloads', 'shop_order', 'normal', 90);
//remove_meta_box('woocommerce-order-label', 'shop_order', 'normal');
}
//Remove postcustom/downloads/shippinglabel meta boxes
add_action('admin_menu', 'remove_custom_field_meta_box');
Try this instead:
add_action( 'add_meta_boxes', 'remove_shop_order_meta_boxe', 90 );
function remove_shop_order_meta_boxe() {
remove_meta_box('postcustom', 'shop_order', 'normal');
remove_meta_box('woocommerce-order-downloads', 'shop_order', 'normal');
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.

load_theme_textdomain using wordpress theme child not working with me

I have problem that I want to load textdomain using child theme.. the function page in the child theme contains only the following code.
<?php
add_action( 'after_setup_theme', 'poseidon_child_setup');
function poseidon_child_setup() {
// Poseidon theme for translation
load_child_theme_textdomain( 'poseidon-child', get_stylesheet_directory() . '/languages' );
}
and this is a part of code of the parent function.php
if (!function_exists('poseidon_setup')) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function poseidon_setup() {
// Make theme available for translation. Translations can be filed in the /languages/ directory.
load_theme_textdomain('poseidon', get_template_directory() . '/languages');
// Add default posts and comments RSS feed links to head.
add_theme_support('automatic-feed-links');
// Let WordPress manage the document title.
add_theme_support('title-tag');
// Enable support for Post Thumbnails on posts and pages.
add_theme_support('post-thumbnails');
// Set detfault Post Thumbnail size.
set_post_thumbnail_size(840, 560, true);
// Register Navigation Menu.
register_nav_menu('primary', esc_html__('Main Navigation', 'poseidon'));
// Switch default core markup for search form, comment form, and comments to output valid HTML5.
add_theme_support('html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
));
// Set up the WordPress core custom background feature.
add_theme_support('custom-background', apply_filters('poseidon_custom_background_args', array('default-color' => 'ffffff')));
// Set up the WordPress core custom logo feature.
add_theme_support('custom-logo', apply_filters('poseidon_custom_logo_args', array(
'height' => 50,
'width' => 250,
'flex-height' => true,
'flex-width' => true,
)));
// Set up the WordPress core custom header feature.
add_theme_support('custom-header', apply_filters('poseidon_custom_header_args', array(
'header-text' => false,
'width' => 2500,
'height' => 625,
'flex-height' => true,
)));
// Add Theme Support for wooCommerce.
add_theme_support('woocommerce');
// Add extra theme styling to the visual editor.
add_editor_style(array('css/editor-style.css', poseidon_google_fonts_url()));
// Add Theme Support for Selective Refresh in Customizer.
add_theme_support('customize-selective-refresh-widgets');
}
endif;
add_action('after_setup_theme', 'poseidon_setup');
I hope help me solve this problem, and I tried to hook some other functions but it seems not working too, but when I leaf a } or ) or ; in the child function.php I got an error and that means the function.php in child file executable but I don't know why nothing work in it.
the languages folder in child theme contains these files:
poseidon.pot
ar.po
ar.mo
You have to use the parent's text domain instead:
// Poseidon theme for translation
load_child_theme_textdomain( 'poseidon', get_stylesheet_directory() . '/languages' );
See this from wordpress docs.

Change Wordpress menu names in child them

My parent theme (html5blank) has 3 menus set up my default in it's functions.php. I want to amend their names in my child theme so they make more sense for my client.
I've tried copying the code into my child theme functions.php and renaming the register_html5_menu function but it won't work as there's no reference to the menus in the templates - presumably because this function is related to the CMS?
Here's the code from the parent theme:
function register_html5_menu()
{
register_nav_menus(array( // Using array to specify more menus if needed
'header-menu' => __('Header Menu', 'html5blank'), // Main Navigation
'sidebar-menu' => __('Sidebar Menu', 'html5blank'), // Sidebar Navigation
'extra-menu' => __('Extra Menu', 'html5blank') // Extra Navigation if needed (duplicate as many as you need!)
));
}
Can anyone think of away to amend the names/possibly add new menus via the child theme functions.php?
Also, what is the second 'html5blank' name for? "Header Menu" is the only thing that shows up in the CMS and I see these 'second comments' throughout the functions file. Just wondering what they do, if anything?
The register_html5_menu() function needs to be called the snippet you provide only defines the function.
Can you try adding
add_action( 'after_setup_theme', 'register_html5_menu' );
to your functions.php file after the function.
On you question about the second 'html5blank' I think is more a question about the translation text function __()
More info here:
https://developer.wordpress.org/reference/functions/__/
Try this
add_action( 'after_setup_theme', 'register_my_menu' );
function register_my_menu() {
register_nav_menu( 'header-menu', __( 'Header Menu' ) );
register_nav_menu( 'sidebar-menu', __( 'Sidebar Menu' ) );
register_nav_menu( 'extra-menu', __( 'Extra Menu' ) );
}

Theme does not take post format file from child theme

I have "post-format" .php file in theme. (templates/blog/). I want to change some thing in this file so that need to add this in child theme.
In child theme, I created folder (templates/blog/) and then paste file. As per my research, I added below code in child theme function.php. Function called proper. but when I run it always take post-format.php file from parent theme instead of child theme.
add_action( 'after_setup_theme', 'setup_postformats', 10);
//add_action( 'after_setup_theme', 'setup_postformats', 20);
//add_action( 'after_setup_theme', 'setup_postformats', 11);
function setup_postformats(){
remove_theme_support('post-formats');
add_theme_support('post-formats', array(
'aside',
'chat',
'gallery',
'image',
'link',
'quote',
'status',
'video',
'audio'
));
}
Theme Name - Lincoln
Can anyone help me out?
I think you need to add the code for include the post-format.php in child theme functions.php file. So it will take the child theme version of post-format.php.
Hope this will solve your issue.
Thanks and Regards
It's important to set the priority for your after_setup_theme higher than your parent theme. The default priority is 10. Using the twentysixteen as example, use priority 11 on child themes. 'after_setup_theme' action. Please refer to the below example:
function twentysixteen_child_setup() {
add_theme_support( 'post-formats', array(
'video',
) );
}
add_action( 'after_setup_theme', 'twentysixteen_child_setup', 11 );
Update
// in your Child Theme's functions.php
// Use the after_setup_theme hook with a priority of 11 to load after the
// parent theme, which will fire on the default priority of 10
add_action( 'after_setup_theme', 'remove_post_formats', 11 );
function remove_post_formats() {
remove_theme_support( 'post-formats' );
add_theme_support( 'post-formats', array( 'video' ) );
}

How to add wordpress image caption to woocommerce archive product (shop) page but not to the single product page

I am using Woocommerce 2.4.4 and Wordpress 4,3, I have read many suggestions for making changes to woocommerce shop page; however I cannot find anyone who addresses my specific request. I have limited understanding of Woocommerce; however I have been trying to solve my request, but to no avail.
I want to display the wordpress caption field for each image in the wordpress media library in my woocommerce shop page but not on the individual products.
I have made changes to my child theme, Deli (A woocommerce theme) functions.php . I added the following to the child functions.php.
function wp_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt',
true ),
**'caption' => $attachment->post_excerpt,**
'description' => $attachment->post_content,
'href' => get_permalink( $attachment->ID ),
'src' => $attachment->guid,
'title' => $attachment->post_title
);
}
I believe the field that has the image caption is 'caption' => $attachment->post_excerpt, as defined above.
I am trying to edit the Woocommerce Archive-product.php but do not know what to add or where to add it in the archive-product.php.
Hey as per your requirement have tried a code which might help you in your case or you can customize it further as per your request.
Add the following code to your Theme's functions.php.
Note: Its better to create a child theme first and do your customization in it so that the customization won't get overwritten when the theme updates.
add_filter( 'wp_get_attachment_image_attributes','wdm_shop_image_caption_func', 10,3 );
function wdm_shop_image_caption_func($attr, $attachment, $size){
if($size=='shop_single'){
unset($attr['title']);
}
elseif($size=='shop_catalog'){
$attr['title']=$attr['alt'];
}
return $attr;
}
Make sure that you set Caption for every Product's Images.

Categories