WooCommerce - Add a Product Search Bar Below the header - php

I can simply add a product search bar right below the header using the following code at the bottom of header.php:
<?php get_product_search_form(); ?>
However since I use the Code Snippets plugin to get all my codes in one place, I needed a function to do that and I found this:
add_action('wp_head', 'your_function_name');
function your_function_name(){
?>
<?php get_product_search_form(); ?>
<?php
};
Unfortunately this function adds the search bar right on top of the header which is not what I want. is it possible to keep it right below the header ?

Related

Wordpress, show or hide header on posts by post categories

Hi i have an wp website and i'm using avada theme. I want to hide header according to its category. For example if posts category is "A" then i dont want to show header on the top automatically. I know i can manually adjust that in the post settings on every posts, or set a layout and select that layout on the below but i dont want to deal that every time.
So i try a if statement in the archives.php.
its something like this:
<?php if(has_category( 'A' )) : ?> //i also try in_category and on_category
<?php else: ?>
<?php get_header(); ?>
<?php endif; ?>
but its probably for category page itself but not for posts.
Can anybody help with that?
Thanks :)
hi you can go with following links and follow the given solution it may worked..
here it show that how to hide specific c***ategorize header post*** ...
https://wpquestions.com/Remove_header_or_styling_from_specific_category_of_posts/11505

Wordpress/PHP: how to place meta tag at top of head

So, I have this PHP function that adds the X-UA-Compatible meta tag to the head of every page of my Wordpress site. (I'm new to Wordpress and PHP so forgive me about terminology). It's in the functions.php file of my StudioPress child theme.
The problem is the tag only works if it's placed very near the top, and the way I have it set up now causes the tag to appear halfway down, so it doesn't work. How can I force this tag to appear at the top of the head of each page?
Ex : You can use wp_head action. The wp_head action hook is triggered within the <head></head> section of the user's template by the wp_head() function. Although this is theme-dependent, it is one of the most essential theme hooks, so it is widely supported.
function aaa_custom_function() {
?>
Your Tag
<?php
}
add_action('wp_head', 'aaa_custom_function', 1000);
Use the third parameter to control the position. Change 1000 to another values to find the perfect position.
Create your custom hook like this way.
open header.php then write this below line where you want to show meta tag
<?php do_action("my_custom_metatags");?>
Now open your functions.php and write down this below code
function my_custom_metatags_fn()
{
//your tag goes here.
}
add_action("my_custom_metatags","my_custom_metatags_fn");
//Test this code it will work like a charm for you.
adding to #Damith answer wp_head action will work.
Refrence
also you can override header.php file into your child theme.
add this code in function.php
<?php function your_custom_function() {
// your custom code which you want to add in header file
}
add_action('wp_head', 'your_custom_function', 1);

Pagebreak using wp_link_pages in Wordpress

I have a php script that reads a text file of 10000 urls one in each line. The script displays all the urls in a blog post. I want the page to be divided into 10 small pages to facilitate comfortabe browsing. So how to add a pagebreak using <?php wp_link_pages(); ?> function inside a post? Something like this:
<?php
echo "Hi, This is First Page";
wp_link_pages();
echo "Hi, This is Second Page";
?>
That isn't how wp_link_pages(); works. It only displays your the_content in pages if your the_content contains this tag <!--nextpage-->
sudo code
<?php
echo apply_filter ("the_content" , "Hi, This is First Page<!--nextpage-->Hi, This is second Page");
wp_link_pages();
?>
You might want to check out this question as to how to retain the page data if you are creating your own page content and not using the standard content area.
Wordpress PHP - need to retain nextpage paginating tag in custom query
When already in a php block, you can execute a function without opening another php block. According to the documentation, wp_link_pages(); should also be called without echo.
wp_link_pages();
Documentation:
https://codex.wordpress.org/Function_Reference/wp_link_pages
This works just fine:
global $post;
$total = substr_count($post->post_content, '<!--nextpage-->') + 1;

How to include php script into header for specific page in wordpress?

I want my script to load only in one certain post page in my blog.
Example page: www.name.com/this-is-cool-post/
How can i call my script if for example my script is in another .php file?
<?php if(is_page('this-is-cool-post')){ ?>
<?php include("myscript.php"); ?>
<?php } ?>
this is not working for me and i don't know where to problem is :S
This may not be the most programmatic way of doing it, but how about creating a custom blog post template, call it blog-specific.php or whatever you want, add the following to the top of it:
<?php
/*
Single Post Template: [Temp Name]
Description: Description of template
*/
?>
Then add your script (<?php include("myscript.php"); ?>) only to this template:
You should then be able to change the template of a particular post in the Single Post Template dropdown option when editing a post:
I think the problem is the location of your script.
If you work on a theme, try to include your script like this
include get_template_directory() . "/path_to_ur_script/script.php";
I hope that help u.

Wordpress custom page code

I'm very new to wordpress and was just wondering if anyone
could point me in the direction of a tutorial which will explain
how to add my own code to wordpress pages.
So far all that I've been able to find is that I'm supposed
to copy the page.php from my template and use that as the
template for a page added in wordpress. This however only
gives me control over the body and not the header/nav menu/sidebar.
Am I correct is assuming I must replace the method calls such as
get_header(), etc with the code it would generate and manipulate
it from there? Also is it correct if I change the arguments to
get_template_part( 'content', 'page' ); and add a php page with
the appropriate name for the body?
Way 1 You can do this:
1) add new page
2) add these code to index.php or page.php
<?php
if (is_page('About 3C')) {?>
<div>Display this particular div</div>
<?php }
else { ?>
<div>Display that particular div</div>
<?php }?>
or
<?php
if (is_page('About 3C')) {
<div>Display this particular div</div>
}
else {
<div>Display that particular div</div>
}
?>
assume your added page name is: About 3C
and you can call the database from above code
OR way 2: please refer:
http://line25.com/tutorials/how-to-create-a-wordpress-custom-page-template

Categories