[Resolved] Add php code to theme

Home Forums Support [Resolved] Add php code to theme

Home Forums Support Add php code to theme

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #340659
    Karim

    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

    #340723
    Leo
    Staff
    Customer Support

    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.

    #340728
    Karim

    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’)

    #340765
    Leo
    Staff
    Customer Support

    I think you have to do something like this: https://codex.wordpress.org/Function_Reference/antispambot#Examples

    #340787
    Karim

    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:)

    #340791
    Leo
    Staff
    Customer Support

    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

    #340807
    Tom
    Lead Developer
    Lead Developer

    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

    #340818
    Karim

    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:)

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.