Add button on Homepage - WordPress Custom Theme - wordpress

I have a website with WordPress custom theme.
Is there any guide how to add a custom button/image on the left side of homepage?
Something eye-catching.

Try below code
add_action('wp_footer','placingButton');
function placingButton()
{
if ( is_front_page() ) {
echo '<div class="button">Your button</div>';
}
}

Related

Link Woocommerce custom placeholder image to product page

On my woocommerce e-commerce page https://www.vattenliv.se/produkt-kategori/filter/ozon-och-proteinskimmer/ there are some products that does not have any product image set. Instead the custom placeholder image shows. Is there a way to make these placeholder images link to each product page, just like the other products?
The site uses the theme OceanpWP and Elementor page builder.
Peter
I believe the best way to do this is by using a child theme, to ovewrite the woocommerce function. This code in your child theme functions.php file should work.
<?php
if (!function_exists('woocommerce_get_product_thumbnail')) {
function woocommerce_get_product_thumbnail($size = 'shop_catalog', $deprecated1 = 0, $deprecated2 = 0) {
global $post;
if (has_post_thumbnail()) {
return ''.get_the_post_thumbnail($post->ID, $size).'';
}
elseif(wc_placeholder_img_src()) {
return ''.wc_placeholder_img( $size ).'';
}
}
}
?>

is_home() like function for Custom Post Type of WordPress

I am using a custom post type name news.
For this purpose, my files are:
archive-news.php
single-news.php
Now I need to trace that I am using news page for some sidebar content issues.
In Wordpress we have this:
is_home()
is_single()
Is there a way to do like this?
is_news_home()
is_news_single()
You can use is_post_type_archive() and is_singular() WP functions.
For the archive-news.php:
if (is_post_type_archive('news')) {
/* code */
}
For the single-news.php:
if (is_singular('news')) {
/* code */
}

How to hide the navigation menu in a single wordpress page?

I have a site powered by wordpress. I need to hide the navigation menu in two specific pages but I couldn´t do it.
This is the page:
The menu is appearing like this:
In the bottom left side of the page. It´s need to be hide or remove.
Above, is the html of the menu
I tried this use this code:
.mob-menu-header-holder .mobmenu .mobmenur-container .mob-menu-left-panel .mobmenu_content .leftmtop .mob-menu-right-panel{display: none;}
Any ideas?
please try add this code in your functions.php
add_action('wp_head', 'add_css_head');
function add_css_head() {
if ( is_page( 'your-page-slug' ) || is_page( 'your-page-slug' ) ) {
?>
<style>
.your-css-class {
display:none
}
</style>
<?php
}
}
if one of page you want to hide is frontpage you can use this
add_action('wp_head', 'add_css_head');
function add_css_head() {
if ( is_front_page() || is_page( 'your-page-slug' ) ) {
?>
<style>
.your-css-class {
display:none
}
</style>
<?php
}
}
First of all you have to access your wordpress files. Then find custom .css or .less file if it's exist. And then add this code line in this file. But this line affect to whole site pages. So, if you want to affect only two pages, you have to add some codes to in your theme's index.php (I guess) file.
.mobmenu{ display:none!important; }

How do I change the title of a Wordpress page within the template?

I am setting up a wordpress theme and it has the "logo" h1 tag at the top which shows the title of the site. On the blog page specifically though I'd like to change the title in the H1 tag.
I am aware there may be some php that does something like this: if blog page show this h1 tag (code) and for every other page show this h1 tag (code).
Is this possible?
Thanks kindly
Please use the below code instead of code which is now using to display the page title.
<?php
if ( is_page( '{enter your blog page slug here}' ) ) {
echo '<h1>{enter your blog page title here}</h1>';
} else {
echo '<h1>{enter your non-blog page title here}</h1>';
}
?>
You can query your current page template with meta.
You can get current page template this meta tag:
_wp_page_template
And full code:
if( get_post_meta($post->ID, '_wp_page_template', true) == "your-template.php" ){
// current page is created with your template
} else{
// other page template or defult template
}
Assuming you have separate template for your blog page, like blog.php in your theme directory.
Then you should follow below code:
if ( is_page_template( 'blog.php' ) ) {
// Current Template is Blog
} else {
// Other Pages
}
More info: http://codex.wordpress.org/Function_Reference/is_page_template
Update:
If blog the one of your page in WordPress then follow below code:
if(is_page('id or slug of WP Blog Page')) {
// This is blog page
} else {
// This is other page
}
If that does not work then you should try including different header files using get_header function.
More Info: http://codex.wordpress.org/Function_Reference/get_header
Suggestion: I would suggest to create new page template for your blog page and then you are good to go. You can refer this to create new page template and assign to page.

Wordpress shortcode - weird position on page

I created shortcode in my child themes functions.php file.
The shortcode is as follows:
function add_login_form() {
if ( is_user_logged_in() )
{
echo 'Witaj zalogowany';
}
else
{
wp_login_form();
}
}
add_shortcode('login_form', 'add_login_form');
I added shortcode [login_form] to my website (test area):
http://s540141209.domenaklienta.pl/wordpress/konto-klienta/
It is added to website after the text:
"TUTAJ POWINIEN BYĆ LOGIN FORM LUB NAPIS „WITAJ ZALOGOWANY”!"
It should be inside first div: <div class="et_pb_row">
But it is shown just after the header of a page. Have you any idea why it happens that way?
Thansk in advance.
But it happens to show before everything on website.
See http://codex.wordpress.org/Shortcode_API on how shortcodes acts. In a shortcode function you should always return the result of the processing done in the shortcode action. Echoing it outputs it as soon as the hook is executed, instead of being inserted in where it should be.
function add_login_form() {
if ( is_user_logged_in() )
{
return 'Witaj zalogowany';
}
else
{
return wp_login_form(array('echo'=>false));
}
}
add_shortcode('login_form', 'add_login_form');
For all arguments of wp_login_form, see http://codex.wordpress.org/Function_Reference/wp_login_form .

Resources