Site logo

Archived topic

Hooks not working in custom template

13 replies · Started by Anonymous on September 30, 2015

Viewing posts 1–14 of 14

Hi Tom,

I have copied the file single.php and changed this.

<?php
/**
 * The Template for displaying all single posts.
 *
 * @package GeneratePress
 */

get_header(); ?>

        <div id="primary" <?php generate_content_class();?> itemprop="mainContentOfPage">
                <main id="main" <?php generate_main_class(); ?> itemtype="http://schema.org/Blog" itemscope="itemscope" role="main">
                <?php do_action('generate_before_main_content'); ?>
                <?php while ( have_posts() ) : the_post(); ?>

                      <?php $meta_values = get_post_meta( get_the_ID() ); ?>
............

I have a hook created in "befor header" . It works fine but not on the page for which I created the template.

Where's the before header hook? If you're just using the built in GP generate_before_header hook, it will be included in the get_header() function you see there, so I don't think the problem is with your single.php file.

Sorry, the Hook is set in "before content"!

Does that hook exist in your custom template?

The hook is available and will work on all sides except on its own single.php and archive.php for the category "vehicles"

Hey Tom,

I've replaced the function <?php get_template_part( 'content', 'single' ); ?> by meta tags. When I insert it again the hooks will run!

Any Ideas...?

When I use <?php do_action( 'generate_before_content'); ?> instead the Hook is working but I have a problem with view.

Normally, the first image should not be loaded.

Please delete the posted URL!

The generate_before_content hook runs inside the content-single.php file.

When making custom page templates, make sure all of the markup/looks are the same, then add your own stuff in over top.

Hard for me to know exactly what's going on without seeing full files, but if you duplicate everything and just add on top of it you shouldn't have any issues.

I can send you both files by email

So I'm not seeing this line anywhere in there: <?php do_action( 'generate_before_content'); ?>

If you want to use that hook, it needs to appear in your custom file wherever you want the hooked content to show up.

When I use <?php do_action( 'generate_before_content'); ?> instead the Hook is working but I have a problem with view.

Normally, the first image should not be loaded.

I'm not sure what you mean by that? Is the page header/featured image being displayed? If so, you should be able to hide it with some CSS quite easily.

Let me know :)

This archived topic is closed to new replies.