Custom Post Header

  • Hi

    I have a problem with the Custom Post Header.

    I used Your code (template) on my test page and it is OK:

    <?php
    $img_src = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), ‘large’, false );
    $categories = get_the_category();

    if ( ! empty( $categories ) ) {
    $cat_name = esc_html( $categories[0]->name );
    }
    ?>
    <div class=”custom-hero”>
    <div class=”grid-container hero-grid”>
    <div class=”hero-column”>
    <h1 class=”entry-title”><?php echo get_the_title( get_the_ID() );?></h1>
    <?php echo ‘term_id ) ) . ‘”>’ . esc_html( $categories[0]->name ) . ‘‘; ?>
    </div>

    <div class=”hero-column”>
    <?php echo ‘‘; ?>
    </div>
    </div>
    </div>

    Then I used the same code on my target page and there it’s not working:
    https://snipboard.io/aQyoOd.jpg

    Kr
    Robert

  • Hi Robert,

    That output means the PHP isn’t being executed on the target site — the code is being printed as text instead of run. The HTML wrapper around it is rendering fine, so the Hook element itself is working and placed correctly; it’s only PHP execution that’s off.

    Two things to check on target domain:

    1. Open the Hook element (Appearance → Elements) and make sure the Execute PHP checkbox is ticked. It’s off by default on a newly created element, so it’s easy to miss when recreating one on a live site.
    2. If instead of the checkbox you see the message “Unable to execute PHP as DISALLOW_FILE_EDIT is defined”, PHP in hooks has been disabled site-wide by a constant in your wp-config.php — often added by a security plugin or by your host. You can re-enable it just for Hook elements by adding this PHP snippet to your site:

    add_filter( 'generate_hooks_execute_php', '__return_true' );

    How to add PHP to your site.
    More on the constant.

    Also double-check the code is in a Hook element — a Block element or a Custom HTML block won’t execute PHP regardless of that setting.

    One more thing: the forum stripped part of your code when you posted it (the <a> tag in the category line was eaten), so I can’t see that line in full. If the above doesn’t sort it, please repost the code wrapped in backticks so it comes through intact.

    Let me know how you go.

  • You right – there was the DISALLOW_FILE_EDIT

    I addes Your PHP code and now it looks OK

    Thx a lot!

    R.

  • Ok, no problem!

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