- This topic has 3 replies, 2 voices, and was last updated 3 years, 1 month ago by
David.
-
AuthorPosts
-
March 1, 2023 at 11:40 pm #2552226
Lars
Hi!
Using this to create navigation search short code:
function generate_navigation_search_shortcode() { // Call the theme's built-in function $navigaion_button = generate_do_navigation_search_button(); $search_form = generate_navigation_search(); $output = $navigaion_button .$search_form; echo $output; } add_shortcode( 'gp_navigation_search', 'generate_navigation_search_shortcode' );Added this inside of a container of generateblocks in a custom created top bar element hook. Web page: https://nyatidensmedicin.se
It’s adding itself outside of the container for some reason. How can I make it be added inside of the top bar container?
March 2, 2023 at 4:16 am #2552514David
StaffCustomer SupportHi there,
shortcodes should
returntheir data and not echo them.
However those functions will need to printed to the screen, so in that case you can use object buffering.
Change the shortcode to:function generate_navigation_search_shortcode() { // start object buffer ob_start(); // Call the theme's built-in function $navigaion_button = generate_do_navigation_search_button(); $search_form = generate_navigation_search(); $output = $navigaion_button .$search_form; echo $output; // return buffer return ob_get_clean(); } add_shortcode( 'gp_navigation_search', 'generate_navigation_search_shortcode' );March 2, 2023 at 11:33 pm #2553634Lars
I am not exactly sure how this code made it work, but it did! I hope to level my PHP-game by the end of the year, or the next one!
I am using an overlay search with another code you have been giving me before in another earlier thread: https://generatepress.com/forums/topic/moving-search-field-and-icon/#post-1540468 but it turns out a bit funny now, this particular time.
You can see the results here:
Shared ImageOr directly through the website (if you click the search icon in the upper right corner):
https://nyatidensmedicin.seThere seem to be some kind of duplication happening and I can’t locate it in the source.
March 3, 2023 at 4:33 am #2553912David
StaffCustomer SupportAh, its because the original search form is still being output.
Instead make your shortcode just output the button.function generate_navigation_search_shortcode() { // start object buffer ob_start(); // Call the theme's built-in function $navigation_button = generate_do_navigation_search_button(); echo $navigation_button; // return buffer return ob_get_clean(); } add_shortcode( 'gp_navigation_search', 'generate_navigation_search_shortcode' );And then style the original form.
-
AuthorPosts
- You must be logged in to reply to this topic.