-
AuthorPosts
-
July 2, 2022 at 9:14 am #1357041
I have inserted a script in the function.php at the enfold child (see below 1:)
Include JavaScript in the head (see below 2:)
After that, a snippet must be included in the head of the page. The conditional tag of WordPress ensures that the code is only loaded within the search.now I do not know where I should embed it
can you help methanks in advance
kind regards
FranzJuly 2, 2022 at 12:53 pm #1357056Hi Franz,
You can add a script to the head section using this code snippet and add it to functions.php of your child theme:
//------------------------------- // Custom script in head section //------------------------------- function custom_script_name(){ ?> <script> // Your script here </script> <?php } add_action('wp_head', 'custom_script_name');
For further information on this topic, please refer to our docs: https://kriesi.at/documentation/enfold/add-custom-js-or-php-script/#add-a-script-to-head-section
Also, the is_search() only triggers when a search result page archive is being displayed.
Best regards,
NikkoJuly 2, 2022 at 11:07 pm #1357096Hello Niko
Thank you very much for your quick reply.
I have done it correctly.below my function.php in the enfold child
Thank you and nice greetings
FranzJuly 3, 2022 at 7:53 am #1357109thank you for the reopening
my question is if I have entered this code correctly
no error appears but the function is not executed
I would like the word to be highlighted and highlighted with a color when doing a text search
thank you and
kind regards
FranzJuly 3, 2022 at 9:06 am #1357110i know some filters ( no scripts ) as child-theme functions.php snippet to use – but they only do highlight the search word in the search-results page.
// highlight search word in results function highlight_results($text) { if (is_search() && !is_admin()) { $sr = get_query_var('s'); $keys = explode(' ', $sr); $keys = array_filter($keys); $text = preg_replace('/('.implode('|', $keys) .')/iu', '<span class="search-highlight">\0</span>', $text); } return $text; } add_filter('the_excerpt', 'highlight_results'); add_filter('the_title', 'highlight_results');
But I would recommend this plugin:
It highlights the search term not only on the search results page, but also on the related links.
https://en-gb.wordpress.org/plugins/highlight-search-terms/July 3, 2022 at 12:26 pm #1357118Hi,
Thanks for helping out @guenni007, maybe a plugin would be a better option for you @schweg33?
Best regards,
RikardJuly 4, 2022 at 7:57 am #1357172hello Rikard
I would also like to thank guenni007
i will use the recommended plugin then.
now this request can be closed
kind regards
FranzJuly 4, 2022 at 1:27 pm #1357200Hi,
Glad Guenni007 could help, thank you Guenni007, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘Include JavaScript in the head’ is closed to new replies.