[Resolved] Trouble executing php with hook element

Home Forums Support [Resolved] Trouble executing php with hook element

Home Forums Support Trouble executing php with hook element

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
  • #1667631

    I have a bit of php code that generates a random collection of 8 letters on the website. Its a fresh install and only have a couple of plugins going. When i save the php for the random string, to my gp child theme, it returns the 8 character string in the top left corner of the site. I want the string to appear in the body of the content, so I copied the php code into the hook element for generate_after_content and clicked the check box for execute php. But the string is not appearing in the body and I dont know why. Help is so appreciated.

    Customer Support

    Hi there,

    can you share a link to a page where the code should be displayed?

    And can you share the code you’re using to display the random letters.


    Thanks for looking into it. Every time the page loads a new random string is shown in the top left of the site, so the code appears to be working. But not working as a hook element.



    //get random string with your desire length

    function getRandom($length){

    $str = ‘abcdefghijklmnopqrstuvwzyz’;
    $str2= ‘0123456789’;
    $shuffled = str_shuffle($str);
    $shuffled1 = str_shuffle($str1);
    $shuffled2 = str_shuffle($str2);
    $total = $shuffled.$shuffled1.$shuffled2;
    $shuffled3 = str_shuffle($total);
    $result= substr($shuffled3, 0, $length);

    return $result;


    echo getRandom(8);


    Customer Support

    Can you try adding some content to the Page ?


    I added some sample text to the page. I tried adding an image but I got an error using two different browsers and different jpg images. Not sure why


    Im checking with my host to resolve the error in uploading images, just in case this is part of the problem with displaying the php hook element.


    I’m doing a fresh WP install. I’ll let you know when i get it all set up again.


    Solved, when I removed the code generating the random string from my theme file and left the identical code in the hook element, with execute php selected, the desired code executed just fine as the hook element. Thanks for the moral support!



    Customer Support

    Glad to hear you found the answer!

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