Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1412189

    Hi,

    I marked in the theme settings to add to the menu a search icon (ajax search:

    yyy

    xxx

    When I hover over it, the URL is https://mysite.de/?s=
    A search keyword has the URL https://mysitet.de/?s=mysearchterm

    I found a snippet how to change the search slug here —>

    function wpb_change_search_url() {
        if ( is_search() && ! empty( $_GET['s'] ) ) {
            wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
            exit();
        }
    }
    add_action( 'template_redirect', 'wpb_change_search_url' );

    But it has no effect on the ajax search field in the main menu, added via theme settings.
    But:
    this snippet change indeed the search slug for the shortcode [avia_search] that I added in a HTML widget of my blog sidebar.

    Could you please tell me how to change the snippet, so that the search slug of the main menu ajax search (added via theme settings) uses the changed search slug, too? (?s= changed to /search/)
    Thank you.

    • This topic was modified 1 year, 4 months ago by BeeCee. Reason: added temp login
    #1412202

    i tested it on one of my pages – but it works that way. https://webers-testseite.de/
    Can we see the page?

    or do you mind the small info field of the browsers when hovering the magnifying glass?

    this hovering has nothing to do with the permalink – and is definitely not as SEO relevant as the permalink on top

    btw: it does not work directly f.e. with german : home_url( "/suche/" )

    but:

    function re_rewrite_rules() {
    	global $wp_rewrite;
    	$wp_rewrite->search_base = 'suche';
    	$wp_rewrite->flush_rules();
    }
    add_action('init', 're_rewrite_rules');
    
    function change_search_url() {
        if ( is_search() && ! empty( $_GET['s'] ) ) {
            wp_redirect( home_url( '/suche/' ) . urlencode( get_query_var( 's' ) ) );
            exit();
        }
    }
    add_action( 'template_redirect', 'change_search_url' );
    #1412207

    My site is not online and I mean that search that is added via theme settings.
    SEO was not my question.

    Type in a search term, it has the URL ?s= that I would like to change to /search/

    Your code doesn’t work for me and that was not my question. Let’s see what the support knows about it.

    #1412209

    please go to that example page and search for : web
    ( that example page is an enfold page ( at 5.6.3 ) –
    https://webers-testseite.de/

    what is the permalink for search-results page ?
    it is: https://webers-testseite.de/suche/web

    #1412213

    As I said: I will wait for the support, so don’t bump my post, I will wait for the support. Your code doesn’t work.

    • This reply was modified 1 year, 4 months ago by BeeCee. Reason: added temp login to my test site
    #1412584

    Hi,

    Thank you for the update.

    The first code above (and @Guenni007’s recommendation) should work, but you need to ensure that you flush the permalink settings by saving the options in the Settings > Permalinks panel.The “Permalink structure” should also be set to “Post Name”.

    Please follow these steps:

    1.) Add the following code to the functions.php file, using the template_redirect hook:

    function ava_change_search_url() {
        if ( is_search() && ! empty( $_GET['s'] ) ) {
            wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
            exit();
        }
    }
    add_action( 'template_redirect', 'ava_change_search_url' );
    

    2.) Go to the Settings > Permalinks panel, select “Post Name” as the permalink structure, and save the changes.

    3.) Remember to clear the cache afterward.

    Best regards,
    Ismael

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.