- This topic has 21 replies, 3 voices, and was last updated 3 years, 4 months ago by David.
-
AuthorPosts
-
December 7, 2020 at 6:55 am #1570461ahmad
Hello Guys
I want to add a search bar hero element under the header bar
like in this image :I have managed to add PHP snippet this one with pluginception
add_shortcode( ‘search_form’, function() {
ob_start();get_search_form();
return ob_get_clean();
} );and then created a hook before the main content and added this :
[search-form]
but the result is ugly not centered and cant color it and doesn’t seem to work:
can you guys help to reach a good result?
best
December 7, 2020 at 7:42 am #1570515DavidStaffCustomer SupportHi there,
create a Block Element and set the Hook to
generate_after_header
https://docs.generatepress.com/article/block-element-overview/
You can use the GenerateBlocks plugin to create the Container, add background etc and other content, to which you can also include your search Shortocde to.
December 7, 2020 at 8:04 am #1570540ahmadThanks for Getting Back David
Alright I was able to get this started
but now how can I alter the look of the search bar itself
– I want to make it longer
– I want to change the button color, shape, size ( rounder, square )
– I want to change the word inside the bar ( Search… )
I cannot do that within the block editor
can you please help?December 7, 2020 at 8:44 am #1570573ahmadAnother Question on mobile
that search bar gets messed up there is no padding between the text field and button
and it’s not centered at all here is how it looks like :December 7, 2020 at 11:09 am #1570702DavidStaffCustomer SupportIf you can share a link to a page where i can see this then ill provide some CSS.
December 7, 2020 at 11:12 am #1570707ahmadSure
Designscanyon.com
Please also check on mobile
ThanksDecember 7, 2020 at 3:58 pm #1570947ElvinStaffCustomer SupportHi,
To clarify: Are you trying to achieve an alignment similar to this?
https://share.getcloudapp.com/Jruq6QPPIf so, you can try adding this CSS:
.gb-inside-container form.search-form { display: flex; justify-content: center; }
This CSS center aligns the contents of the search form.
December 8, 2020 at 12:34 am #1571216ahmadThank you, Elvin
that fixed the alignment for surecan you please tell me how to change:
– button color
– the wording inside the search boxalso for some reason on mobile the text field has rounded corners but on the desktop is different
do you know why and how to make it corners on all devices?Thanks
December 8, 2020 at 3:10 am #1571375DavidStaffCustomer SupportTo change the Placeholder text you will need to change your search from shortcode to this:
add_shortcode( 'search_form', function() { ob_start(); ?> <form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>"> <label> <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) ?></span> <input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" /> </label> <input type="submit" class="search-submit" value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>" /> </form> <?php return ob_get_clean(); } );
On this line of the code:
placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder' ) ?>
Change the
Search ...
text to what you require.
Once that is done we may need to tweak the CSS – so make that change and let us know and we can work through the other amends.December 8, 2020 at 3:14 am #1571376ahmadHello David Yes that worked Thank you
still left:
-Change button Color
-fix the rounded text field in mobile
Best
December 8, 2020 at 3:15 am #1571378ahmadalso if there is a way to make the search field width longer ?
December 8, 2020 at 6:14 am #1571538DavidStaffCustomer Supporthmmm … you’re using a Grid Block with empty columns to restrict the size of your content. Don’t use the Grid Block, simply place the content inside the Container block, in the settings > Layout you can change the width of the inner container.
Need that change so as i can resize the search bar.
December 10, 2020 at 1:28 am #1573978ahmadCan you please tell me how to change the button color?
ThanksDecember 10, 2020 at 4:28 am #1574158DavidStaffCustomer SupportBy default that button will use the Colors you set in Customizer > Colors > Buttons
If you want it to be different to the rest of the theme then use this CSS:.search-form input[type=submit] { background-color: #f00; color: #000; }
December 10, 2020 at 4:45 am #1574185ahmadThank you David that changed the color!
The only thing I have left is the actual width of the search field I would like to make it longer.
I did what you said in the block editor I removed all the columns as a test and keep only the short code one but still, it was the same width it wasn’t longer
any ideas what could be the issue?
Best
-
AuthorPosts
- You must be logged in to reply to this topic.