[Resolved] Hooks not working in custom template

Home Forums Support [Resolved] Hooks not working in custom template

Home Forums Support Hooks not working in custom template

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #141050
    Andreas

    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.

    #141101
    Tom
    Lead Developer
    Lead Developer

    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.

    #141139
    Andreas

    Sorry, the Hook is set in “before content”!

    #141186
    Tom
    Lead Developer
    Lead Developer

    Does that hook exist in your custom template?

    #141201
    Andreas

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

    #141205
    Andreas

    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…?

    #141229
    Andreas

    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!

    #141240
    Tom
    Lead Developer
    Lead Developer

    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.

    #141245
    Andreas

    I can send you both files by email

    #141247
    Tom
    Lead Developer
    Lead Developer

    Might be easier to upload them using http://pastebin.com/.

    #141251
    Andreas
    #141255
    Tom
    Lead Developer
    Lead Developer

    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.

    #141264
    Andreas

    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.

    #141336
    Tom
    Lead Developer
    Lead Developer

    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 🙂

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