Archived topic
Add php code to theme
7 replies · Started by Karim on June 28, 2017
Hello there:)
I have a quick question.
I just learned there's a built in "Antispam" function in Wordpress which can be activated by adding this code anywhere in the theme: <?php antispambot('heregoesyouremail') ?>
I tried to add this code with the code snippets plugin you mentioned in some post, but it gives an error.
My question is: can i also execute/activate this piece of code with the Hooks build in the theme? If yes, in which part would you suggest?
Or should i use a child theme? I never used a child theme before, but i know the idea of it. How does it work, can i add the code in the functions.php file and that's it?
Hope to hear from you.
Thanks:)
Karim
Hi there,
What error did you get using Code Snippets? Generally that's the best way.
Just want to make sure you won't get the same error using other methods as well.
Hello Leo:)
Thanks for quick reply.
I get this error: "The snippet has been deactivated due to an error on line 1:
syntax error, unexpected end of file"
When i place the code it is like this: <?php antispambot('myemail') ?>
But when i hit save and activate it gives me the above error and the php tags are gone. So it looks like this: antispambot('myemail')
I think you have to do something like this: https://codex.wordpress.org/Function_Reference/antispambot#Examples
Not sure which pieces of code i need of those. But i know you already give so much more support for something which is not your product. Respect for that:)
Ahh no. Looks like you just missed echo and a semicolon:
<?php
echo antispambot( 'john.doe@mysite.com' );
?>
https://codex.wordpress.org/Function_Reference/antispambot#Default_Usage
I think the point of that is to make a shortcode which you can then use anywhere in your content.
That's what they're suggesting here: https://codex.wordpress.org/Function_Reference/antispambot#Examples
Give me some more time and soon i hope i understand more of this coding stuff:)
For now, i just i think i have to resort back to using a plugin for this.
Thanks guys:)