Archived topic
A header element is not working because it converts <?php to <--?php
5 replies · Started by Elías Gómez on May 29, 2021
I have a header element called "Single Post Entry Header" that was created when installing a template from the Site Library. A few days ago it started to get broken, showing code on the frontend:

This is the code:
<div id="custom-post-entry-header" class="custom-post-header grid-container">
<?php
$categories = get_the_category();
$separator = ' | ';
$output = '';
var_dump($categories);
if ( ! empty( $categories ) ) {
foreach( $categories as $cat ) {
$name = $cat->name;
$output .= '<a href="' . esc_url( get_category_link( $cat ) ) . '" alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $name ) ) . '">' . esc_html( $name ) . '</a>' . $separator;
}
echo trim( $output, $separator );
}
the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' );
if ( has_excerpt() ) : // Only show custom excerpts not autoexcerpts ?>
<p class="entry-subtitle"><?php echo get_the_excerpt(); ?></p>
<?php endif; ?>
</div>
The problem is that the first PHP opening tag is changed to <-- so it becomes a comment, and then where $category->name the -> becomes to --> so it closes the comment.
If I disable the Element and create it in Code Snippets it works great.
Why is this happening? Can you fix it?
Thanks
Hi there,
in the Hook Element - make sure you have enabled Execute PHP ( Ejecutar PHP ).
Oh, it turns that iThemes Security disabled the "File edition permission", so the "Execute PHP" in the Elements module. I didn't realize 🤦♂️ Why is that happening? Editing is not the same as executing, maybe you shouldn't check for that directive.
Thank you very much!
You can set ALLOW just for the Hook Element:
https://docs.generatepress.com/article/generate_hooks_execute_php/
Perfect, I've applied it.
Glad to be of help