[Resolved] I added a Hook to a Category Archive Page; Code is visible

Home Forums Support I added a Hook to a Category Archive Page; Code is visible

  • This topic has 7 replies, 4 voices, and was last updated 5 months ago by David.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1157260
    Elaine

    I created an action hook using your documentation, and using an Element. This is to add a photo to the top of the category page. I must be doing something wrong because the code is visible on the front end!

    #1157337
    Leo
    Staff
    Customer Support

    Hi there,

    Sorry what’s the code you are adding?

    If it’s PHP then make sure to check execute PHP.

    Let me know 🙂

    #1157757
    Elaine

    Thanks Leo. You were right, I did not execute PHP. However, when I do execute PHP in Elements, now there is an error on the front end, and it breaks the page:
    Parse error: syntax error, unexpected ‘}’ in /home1/chance/public_html/wp-content/plugins/gp-premium/elements/class-hooks.php(180) : eval()’d code on line 4

    Here is my original code:

    add_action( 'generate_before_main_content','es_insert_photo' );  
    function es_insert_photo() { ?> 
         <img src="/wp-content/uploads/cheers.jpg" alt="Glasses of wine clinking together among friends." />
    <?php }
    #1157830
    David
    Staff
    Customer Support

    Hi there,

    you don’t need to use the add_action function as this is what the Hook Element is doing.
    You simply need to add the Content you wish to display eg.

    <img src="/wp-content/uploads/cheers.jpg" alt="Glasses of wine clinking together among friends." />

    Select the before_main_content hook from the list.

    This won’t require Execute PHP to be checked

    #1157841
    Elaine

    Thanks David, that worked I was overthinking it!

    #1157842
    David
    Staff
    Customer Support
    #1161227
    Melissa

    David,
    We have a related question to this topic and getting similar parse error or visible code on site. Could you please provide an example for an instance such as ours when you do need to execute PHP within the Hook Elemnt? We are trying to remove_action / add_action in order to move secondary nav to above footer but have tried 50 ways to Sunday to make it work and nada. From GP’s forum in 2014 Tom assisted someone when it was just the HOOKs method, but using ELEMENT has us scratching our heads. The basic content functionality we want to implement below while using Hook “before_footer”. Thanks so much!

    {
    remove_action( ‘generate_before_header’, ‘generate_add_secondary_navigation_before_header’ );
    add_action( ‘generate_before_footer’, ‘generate_add_secondary_navigation_before_header’ );
    }

    #1161593
    David
    Staff
    Customer Support

    Hi there,

    so moving the Secondary Nav to a new hook using Elements would require two things:

    1. In Customizer > Layout > Secondary Navigation – set the Location to: No navigation. This is the equivalent of the remove_action call

    2. For your Hook Element you can use this snippet to call the secondary navigation:

    <?php 
    if ( function_exists( 'generate_secondary_navigation_position' ) ) {
    	generate_secondary_navigation_position();
    }
    ?>
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.