• Resolved wissam6

    (@wissam6)


    Hi,
    For a certain reason I have a page which looks like that (a lot of texts):
    Chap1
    Section 1
    S2
    S3

    Chap2
    S1
    S2

    The search works fine, as well as the excerpt.
    The problem is in the result: the user doesn’t know in which chapter the result is, he can see indeed a small resume but he cannot know in which chapter unless he open the page and he search the highlighted word in the entire page.
    Is there any way to solve this?
    thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Yes, see here for instructions on how to make the page scroll to the first search result. In general the browser in-page search is the best solution, though.

    Thread Starter wissam6

    (@wissam6)

    thx
    If I understood correctly, tou are saying that either we use javascript code or the function wp_enqueue_script(), right?

    the JavaScript code should be on my page? on each page?
    and wp_enqueue_script()? where i should write it?

    thank you in advance

    Plugin Author Mikko Saari

    (@msaari)

    The Javascript code needs to appear in the single post page. There are many ways to get it in there, but the best way is to put the code in a separate file inside your theme and then use wp_enqueue_script() in your theme functions.php to load the script. This would load the file /js/example.js inside your theme folder:

    function wpdocs_theme_name_scripts() {
        wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
    }
    add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
    Thread Starter wissam6

    (@wissam6)

    first i tried to put the js code on the page, i have this error :
    Uncaught ReferenceError: getParams is not defined

    Thread Starter wissam6

    (@wissam6)

    after i integrated the javascript code in the header of every page i see that it doesn’t work, i mean from my result page if i open the page it doesn’t scroll down automatically.

    do you think because of incompatibility of javascript and arabic text?
    i think so, because the function in the javascript which read the url return text like https://arabiccatholicbible.com/project/luke/?highlight=%D8%AF%D8%A7%D9%88%D8%AF instead of the real word in arabic.

    is there a workaround?

    • This reply was modified 3 years, 8 months ago by wissam6.
    • This reply was modified 3 years, 8 months ago by wissam6.
    • This reply was modified 3 years, 8 months ago by wissam6.
    Thread Starter wissam6

    (@wissam6)

    oh yes it works!
    the answer is that we have to use the decodeURIComponent if we have arabic text in the url:

    replace the line
    window.location.href.replace( location.hash, ” ).replace(
    by
    decodeURIComponent(window.location.href).replace( location.hash, ” ).replace(

    hope it will be useful for the others
    thx

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘search result in a section’ is closed to new replies.