Hoping someone out there who is familiar with Genesis hooks can give me a quick solution. I am not very familiar with PHP
In the child theme's functions file I have this:
/** Add the featured image section */
add_action( 'genesis_after_header', 'full_featured_image' );
function full_featured_image() {
if ( is_front_page() ) {
echo '<div id="full-image"><img src="'. get_stylesheet_directory_uri() . '/images/home-header.jpg" /></div>';
}
}
I just want to change the front page image from the static one (images/home-header.jpg) to the featured image for the home page. What should I change in here?
Thanks in advance.
Kitka
Related
How can I add an image to the "real place" theme in WordPress?
I thought of adding the following code in functions.php:
<img src="<?php echo get_template_directory_uri(); ?>/wp-content/uploads/2023/02/banner.jpg" />
banner.jpg image is inside media folder in WordPress. How can I add a banner.jpg image to the "real place" theme in WordPress? Is it right to add some code inside the function.php file in the "real place" template?
Below code adds an image to the header of your site using the wp_head action (only on the home page as per your comment):
function add_banner_image() {
if ( is_front_page() ) {
echo '<img src="URL_OF_YOUR_IMAGE" />';
}
}
add_action( 'wp_head', 'add_banner_image' );
Hi I'm trying to create a custom plugin that will display the main product image from Woocommerce plugin. I want to use shortcode. How do I go about doing this? This is what I had and it didn't work. I've also found different suggestions. I will share everything below
add_shortcode( 'product_image', 'bbloomer_product_image_shortcode' );
function bbloomer_product_reviews_shortcode() {
return woocommerce_get_product_thumbnail();
}
<?php
$gallery_shortcode = '[gallery id="' .intval($post->$post_parent).'"]';
print apply_filters('the_content', $gallery_shortcode);
?>
These are what I found/were suggested to me before
try this:
$featured_image = wp_get_attachment_url( get_post_thumbnail_id($product_id));
How to make all the featured image clickable automatically? As it's Wordpress theme, I can only edit php or add css.
Simply add this code to your theme’s functions.php file.
This code simply adds a link around the code generated to display featured images or post thumbnails on your website.
function wpb_autolink_featured_images( $html, $post_id, $post_image_id ) {
$html = '' . $html . '';
return $html;
}
add_filter( 'post_thumbnail_html', 'wpb_autolink_featured_images', 10, 3 );
This code will also add a link around featured images on single post pages. If you don’t want to link featured images on single post to the same post, then use this code.
function wpb_autolink_featured_images( $html, $post_id, $post_image_id ) {
If (! is_singular()) {
$html = '' . $html . '';
return $html;
} else {
return $html;
}
}
add_filter( 'post_thumbnail_html', 'wpb_autolink_featured_images', 10, 3 );
Normally the functionality of a featured image has no link attached to it. Different themes use the functionality of featured image differently. The new Twenty Nineteen theme, for example, uses it as the background for the page header, behind the post title.
So it will be better to make a child theme of your parent theme and edit the php file to set a link. Without editing the code you cannot set the link of the featured image.
Insert image > Click on the desired cell you want to insert it > Down on the right: “Linked to” > Personalized URL.
I am using WordPress 4.9.6.
I have set the shop page to be the home-page.
How do I add a page banner to the shop page. I would like to add it just above the breadcrumb trail.
I have tried adding this to the following page archive-product.php
if (is_shop()) {
$args = array('taxonomy' => 'product_cat');
$product_categories = get_categories( $args );
$term_id = $product_categories[0]->term_id;
$content = get_term_meta($term_id, 'cat_meta');
if(isset($content[0]['cat_header'])){
echo do_shortcode($content[0]['cat_header']);
}
}
Unfortunately, not able to add any image to the page.
You can achieve using 2 methods.
1) Add your static image directly at the beginning of archive-product.php
echo "<img src='{YOUR_IMAGE_PATH}'>";
2) Add filter in your theme's functions.php file.
add_action ('woocommerce_archive_description' , 'shop_banner',99);
function shop_banner() {
echo '<img src="{YOUR_IMAGE_PATH}" >';
}
I'm not so sure if I understand exactly what you want. But this is what I understand so far.
If you want to display an Static image banner above the breadcrumbs in your Shop Page.
You could use the woocommerce_before_main_content action.
function BannerShop(){
if(is_shop()){
echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
}
}
add_action( 'woocommerce_before_main_content', 'BannerShop', 10 );
Here i show the before and after. BTW I don't know what theme are you using so it may be displayed different.
Before
https://i.stack.imgur.com/Mv2YK.jpg
After https://i.stack.imgur.com/nTfCa.jpg
I'm using WordPress 4.9.4 running Twenty Seventeen Child Theme theme with Woocommerce Version 3.3.4. I am trying to remove the sidebar… I have tried using this:
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',10);
But haven't found the right one yet.
How do I remove all sidebars?
The best and simple way that works with all themes is to use the get_sidebar Wordpress action hook this way:
add_action( 'get_sidebar', 'remove_woocommerce_sidebar', 1, 1 );
function remove_woocommerce_sidebar( $name ){
if ( is_woocommerce() && empty( $name ) )
exit();
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
You might need to make some CSS changes on some html related containers
This code works on any theme as all themes use get_sidebar() Wordpress function for sidebars (even for Woocommerce sidebar) and get_sidebar action hook is located inside this function code.
WooCommerce ads the side bar in code directed at this specific theme, in class WC_Twenty_Seventeen
/**
* Close the Twenty Seventeen wrapper.
*/
public static function output_content_wrapper_end() {
echo '</main>';
echo '</div>';
get_sidebar();
echo '</div>';
}
I used this code to replace that function
remove_action( 'woocommerce_after_main_content', array( 'WC_Twenty_Seventeen', 'output_content_wrapper_end' ), 10 );
add_action( 'woocommerce_after_main_content', 'custom_output_content_wrapper_end', 10 );
/**
* Close the Twenty Seventeen wrapper.
*/
function custom_output_content_wrapper_end() {
echo '</main>';
echo '</div>';
echo '</div>';
}
Use the is_active_sidebar hook - this should work in any theme as it's core WordPress functionality:
function remove_wc_sidebar_always( $array ) {
return false;
}
add_filter( 'is_active_sidebar', 'remove_wc_sidebar_always', 10, 2 );
You can also use conditional statements to only hide the sidebar on certain pages, e.g. on Product pages:
function remove_wc_sidebar_conditional( $array ) {
// Hide sidebar on product pages by returning false
if ( is_product() )
return false;
// Otherwise, return the original array parameter to keep the sidebar
return $array;
}
add_filter( 'is_active_sidebar', 'remove_wc_sidebar_conditional', 10, 2 );