Automatically Pass Search Terms to Custom Google Search on 404 Pages

Is there a simple way to pass the 'search' terms which landed a user on a 404 page to Custom Google Search? The Custom Google Search box is already present on the 404 page, so I would think it would just be a matter of making a few small edits to pass the terms that landed the user on the page to the plugin to run the search.

[This might also be a useful feature request.]

  • Vinod Dalvi
    • WP Unicorn

    Hi Zyniker,

    I hope you are well today and thanks for posting on the forum.

    Do you want to just display the 'search' word in the Custom Google Search text field on 404 page?

    Could you please share your site URL where you are using it so that i can provide you custom solution to achieve it?

    I will move this over to the features & feedback section. This way it can be considered for future development, and we can also see what other community members think about the feature request.

    Kind Regards,
    Vinod Dalvi

  • Vinod Dalvi
    • WP Unicorn

    Hi Zyniker,

    Thank you for your reply.

    I have not tested it but you can try achieving it as described here by customizing the Custom Google Search form as following.

    $search_word = '';
    if ( is_404() ) {
    	$url = $_SERVER["REQUEST_URI"];
        $tokens = explode('/', $url);
    	$search_word = $tokens[sizeof($tokens)-1];
    <form id="cse-search-box" action="" method="get">
    <input type="text" name="q" autocomplete="off" size="30" value="<?php echo $search_word; ?>" /> 

    Vinod Dalvi

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.