Title: functions.php and index.php question
Last modified: August 19, 2016

---

# functions.php and index.php question

 *  [wp-rory](https://wordpress.org/support/users/wp-rory/)
 * (@wp-rory)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/functionsphp-and-indexphp-question/)
 * Hi all,
 * I have just moved a WordPress site from one domain on a 2.8.1 installation to
   another domain with a fresh 2.8.4 installation, using my usual method of importing
   the posts, pages, etc and then copying the themes and plugins across via FTP.
   I had an undefined function error on the new index page which I fixed by adding
   the user-defined function (‘get_first_image’) code I want on the website to the
   functions.php file on the new installation. The code is the same as that which
   was in the old functions.php file (please find below).
 * Now, although the error message has gone, the function is not working properly.
   It should be getting the first image from each post but it is not doing so. The
   images are there in each post but they are not being displayed on the index(.
   php) page where they are being called with my normal `<?php get_first_image();?
   >` code.
 * Does anybody know if I am missing something here? Do I have to define the function
   or change some code elsewhere within the WordPress installation? It is a while
   since I made the website but have to now put it on a different domain so I can’t
   remember if I had to change anything else.
 * Any help would be greatly appreciated!
 * All the best,
 * Rory. 🙂
 * p.s. The code of the custom get image function in the functions.php file – `/**
   GetFirstImage Function **/
 * function get_first_image() {
    $files = get_children(‘post_parent=’.get_the_ID().’&
   post_type=attachment&post_mime_type=image’); if($files) : $keys = array_reverse(
   array_keys($files)); $j=0; $num = $keys[$j]; $image=wp_get_attachment_image($
   num, ‘large’, false); $imagepieces = explode(‘”‘, $image); $imagepath = $imagepieces[
   1]; $thumb=wp_get_attachment_thumb_url($num); print “<img src=’$thumb’ class=’
   thumbnail’ />”; endif; }`

Viewing 1 replies (of 1 total)

 *  Thread Starter [wp-rory](https://wordpress.org/support/users/wp-rory/)
 * (@wp-rory)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/functionsphp-and-indexphp-question/#post-1200488)
 * OK I seem to have fixed it – it was just a problem with the images in the posts
   on the new site. Just changing their URLs wasn’t enough – when I deleted them
   and re-uploaded them, they appear on the index page as they should.
 * All the best,
 * Rory. 🙂

Viewing 1 replies (of 1 total)

The topic ‘functions.php and index.php question’ is closed to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [wp-rory](https://wordpress.org/support/users/wp-rory/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/functionsphp-and-indexphp-question/#post-1200488)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
