WordPress.org

Forums

How to add image to 404 error page (9 posts)

  1. Uendi
    Member
    Posted 1 year ago #

    Hi

    I have added some message to this 404.html error page, but how to add image (e.g fruits) to make it looks professional ?

    Anybody knows how to do it ?

    Thanks.

  2. Aureola
    Member
    Posted 1 year ago #

    Are you developing your own theme/changing an existing one..? In that case I think you need to edit your 404.php file. and add this where you want the image to appear:
    <img src="<?php bloginfo('template_directory'); ?>/images/imagename.png" alt="" />
    (of course you need the path to your image from the theme directory and down.)

  3. Uendi
    Member
    Posted 1 year ago #

    Actually, I am creating 404.html in the file manager under cpanel, that is why I do not know how to add an image in it.

  4. Aureola
    Member
    Posted 1 year ago #

    I'm not sure that that is how it can be done (but I might be wrong).
    Reading this: http://codex.wordpress.org/Creating_an_Error_404_Page
    there is no html file. just php.

    In a normal page that you create in the admin panel, to add a picture you just press the Add Media button in Visual mode and select the picture.

  5. Uendi
    Member
    Posted 1 year ago #

    May be it works.

    <img src="<?php bloginfo('template_directory'); ?>/images/imagename.png" alt="" />

    Lets say, my site is example.com and the image is fruits.png, then how to add in it to the above-mentioned code ?

  6. Aureola
    Member
    Posted 1 year ago #

    You have to know where in the directory structure you have put your image.

    If let's say this is your path:
    example.com/wp-content/themes/UendisTheme/images/fruits.png

    then in your 404.php file add
    <img src="<?php bloginfo('template_directory'); ?>/images/imagename.png" alt="The image alt-text" />
    (since example.com/wp-content/themes/UendisTheme is replaced by 'template_directory'.

  7. Uendi
    Member
    Posted 1 year ago #

  8. Aureola
    Member
    Posted 1 year ago #

    Read a bit about the bloginfo function on http://codex.wordpress.org/Function_Reference/bloginfo and see if you can figure it out yourself. Clearly you need to have something else there than template_directory. Maybe ('wpurl').

  9. NYM1
    Member
    Posted 11 months ago #

    Just in case anyone comes across this thread and needs the info,
    I added an image to my error page by adding this code to my 404.php over my header tags:

    [...<img class="aligncenter size-thumbnail wp-image-7938" src="http://example.com/wp-content/uploads/2014/04/sad-kitty-300x187.png" alt="sad-by-Apple-Nek"/>...]

    Obviously I used my real image path rather than the example path shown above.
    Make sure you don't include the [... and ...] when you cut & paste.

Topic Closed

This topic has been closed to new replies.

About this Topic