How can I add an image to the "real place" theme in wordpress? - php

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

Related

WP theme Genesis child - show featured image on home page?

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

How to make featured image clickable? -Wordpress

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.

Adding an image page banner to shop page

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

Add text in this PHP code?

function woocommerce_template_product_description() {
wc_get_template( 'single-product/tabs/description.php' );
}
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_product_description', 20 );
This code prints a product description, but I'd like to add the text "Description:" before the description itself without having it on a separate line. How do I go about that? I am a total beginner when it comes to coding. Thanks!
In WordPress/WooCommerce Product are nothing but a Post. So the the product
description is treated as the_content of a post.
If you just want to add custom text/content before the Product Description then just use the_content filter.
Here is the code.
function theme_slug_filter_the_content($content)
{
//Only for single product page.
if (is_product())
{
$prepend = 'Description';
$content = $prepend . $content;
}
return $content;
}
add_filter('the_content', 'theme_slug_filter_the_content', 9); // <-- Choose some priority <
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and fully functional.
Reference
the_content
is_product
You have to locate the template file and edit the template file, so that it renders the desired output.
This loads a template file only
You need to edit that specific file "single-product/tabs/description.php"
and add a echo there.
Case-1 : Add "Description" in tab
Path : templates/single-product/tabs/description.php
<?php echo "<b>Description</b>"; the_content(); ?>
Case-2 : Add "Description" in Short description area
Path : templates/single-product/short-description.php
<?php echo "<b>Description</b>"; ?>
<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ) ?>

Wordpress: how to create a section with editable text in theme customization?

I am experimantating with creating wordpress theme's.
In much pre made theme's you can edit text or other options for a section in the theme customize menu.
I did google a bit for it but my results weren't the ones I need.
Does anyone know how to reach this?
you can create your own theme option page. This link will help you
https://codex.wordpress.org/Creating_Options_Pages
Example code
Creating a Theme Settings Page Menu Item
function theme_settings_page(){}
function add_theme_menu_item()
{
add_menu_page("Theme Panel", "Theme Panel", "manage_options", "theme panel", "theme_settings_page", null, 99);
}
add_action("admin_menu", "add_theme_menu_item");
Here is the code for the theme_settings_page function to create a section and add the submit button.
function theme_settings_page()
{
?>
<div class="wrap">
<h1>Theme Panel</h1>
<form method="post" action="options.php">
<?php
settings_fields("section");
do_settings_sections("theme-options");
submit_button();
?>
</form>
</div>
<?php
}
Uploading a Logo
function logo_display()
{
?>
<input type="file" name="logo" />
<?php echo get_option('logo'); ?>
function handle_logo_upload()
{
if(!empty($_FILES["demo-file"]["tmp_name"]))
{
$urls = wp_handle_upload($_FILES["logo"], array('test_form' => FALSE));
$temp = $urls["url"];
return $temp;
}
return $option;
}
function display_theme_panel_fields()
{
add_settings_section("section", "All Settings", null, "theme-options");
add_settings_field("logo", "Logo", "logo_display", "theme-options", "section");
register_setting("section", "logo", "handle_logo_upload");
}
add_action("admin_init", "display_theme_panel_fields");
If you know CSS and Html just fallow the two steps
Open the child theme style.css file in your text editor. (Or skip the
FTP and text editor and just go to your WordPress admin area,
Appearance => Editor, and click on style.css on the right side).
Open your site in Google Chrome, and open the Dev Tools (right-click
and select “inspect element”).
If you dont aware about php, html, css etc. Follow the below link
click me to customize wordpress
And Most of the Theme having Theme documentation you should follow the steps inside the theme documentation to change by theme options.

Categories