• Resolved Marouane87

    (@marouane87)


    Hello,

    I really appreciate the help provided through the many threads I’ve opened ?? ! But I still have a question please.
    I want to change the 404 page to show a personalized image and keep the search form, I’ve found the snippet (provided by Nicolas) to add slides, but couldn’t figure out how to change it to show the personalized picture and keep the search form… Here is my “try”…

    add_filter('tc_show_image' , '__return_true' );
    add_filter('tc_image_name_id' , 'set_image_name');
    function set_image_name( $original_name ) {
    if ( ! is_404() && ! is_search() )
    return $original_name;
    return 'image_404.jpeg';//<= write the name of your slider here
    get_search_form( $echo = false );
    }

    Thank you very much!

Viewing 10 replies - 1 through 10 (of 10 total)
  • I would also like to know how to customize the 404 page.

    mm @marouane87 you invented “tc_show_image” and “tc_image_name_id” that’s why nothing happens.
    Nicolas’ snippet was to show a slider in that page, create a slider and use that snippet.
    Do you want something like:
    [slider]
    [missing page alert]
    [search]
    ?

    Thread Starter Marouane87

    (@marouane87)

    I thought maybe it was the same, my mistake ?? !

    No need for slider, just:
    [missing page alert] (which is the personalized picture)
    [Search]

    Thank you very much!

    Try this then,

    add_filter('tc_404_content', 'my_404_content');
    function my_404_content(){
        $image_url = 'REPLACE THIS WITH YOUR IMAGE URL';
        return sprintf('<img alt="Not Found" class="404-img" src="%1s">%2$s',
            $image_url,
            get_search_form( $echo=false)
        );
    }

    Thread Starter Marouane87

    (@marouane87)

    Thank you very much! One final request please, is it possible to display the same when a search request has no result?

    Thank you again ?? !

    You’re welcome.
    Just add also this to your child-theme functions.php

    add_filter('tc_no_result_content', 'my_404_content');

    This will point to the same function my_404_content.

    Thread Starter Marouane87

    (@marouane87)

    Thank you very much!

    In case someone wants to delete “No Search Results for : nothing” and the glass icone (like me), just add

    add_filter('tc_search_results_header_content', 'my_no_result');
    function my_no_result(){
        return;

    (Yes, I’m learning to write small functions ?? !)

    Oh great you took a look at the hooks api ??
    ( You’re on the right track… so don’t delude me ?? )

    Unfortunately the hook tc_no_results_content_icon, as the name suggests, is about an icon you already don’t display because we get rid of the original content with the code I posted above.
    You’re interested about some Headings filters like:

    add_filter('tc_search_results_header_content', 'change_search_title');
    function change_search_title($header){
        /* with this if you change the search title when there are no results */
        if ( is_search() && ! have_posts() ){
           $new_title= '<h1>My New No result title</h1>';
           return preg_replace('|<h1.*?</h1>|', $new_title,$header);
        }
        return $header;
    }

    Hey, you edited that message a bunch of time, making my reply useless ??
    I’m glad you’re learning ??

    Thread Starter Marouane87

    (@marouane87)

    I’m sorry about that, I was trying after I posted the question, so I updated my last message depending on my progress ?? !

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Customize page 404’ is closed to new replies.