WordPress functions.php

I am following the instructions in 6 Practical WordPress Projects as regards putting together a non-blog WordPress website. Consequently, I have copied and pasted the code provided by the book to functions.php, as instructed.

Unfortunately, doing this returns a ‘fatal error’.

My functions.php file contains no other code except the code that I copied and pasted from 6 Practical WordPress Projects. (I have, of course, added the opening php tag as required, though I understand that the closing tag is not required.)

Perhaps someone can help me fix this problem?

The code is as follows:

If nothing else, > should be >

Seems you didn’t get my reply, sent about 12 hours ago. Here it is again:

Thanks for replying so quickly.

So, to confirm, you are saying that the last line of code should be:

$wp_query- > set_404(); //404 not found

(I presume the spaces in your reply are significant.)

Ah thanks for picking that up @rpkamp.

@Simon_Mackie it looks like we have an encoding error in at least this part of the course.

There should be no space between the - and the >. It is a single operator ->.

Thank you for your indulgence. I’ll do my best to correct the code and report back. Since everything was working fine until I uploaded functions.php as reported, I am confident that the only error was in functions.php.

1 Like

Your correction has worked, Gandalf, so all is well in my world now. What I have learned in the process is that it is a good idea to add function code snippets to functions.php one at a time, and to test them one at a time.

3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.