[Resolved] GP Page Headers Standalone Shortcode or PHP Call

Home Forums Support [Resolved] GP Page Headers Standalone Shortcode or PHP Call

Home Forums Support GP Page Headers Standalone Shortcode or PHP Call

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #491680
    vr51

    I want to assign a page header to all posts within a specific category.

    I can set which header to display on the archive page using Categories > Cat. Name > Edit > Set Header but I can’t see a GUI way to globally set a specific header to display above any single post assigned to a specific category.

    I’ve looked through the plugin code but can’t see a function that tells the theme which header to display and when to display it.

    Is there a shortcode I can use or function I can call to display a header within a specific page or post?

    I’m looking to do Something similar to (or the shortcode equivalent of):

    <?php
    if ( ! is_archive() && function_exists('relevant-gp-function') && is_single() && in_category('') ) {
        relevant-gp-function('header-ID'); // Print header with post ID
    }
    ?>

    Can it be done?

    #491825
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Currently this can’t be done, but we do plan on filtering the $id variable in GPP 1.6 which should make this do-able: https://generatepress.com/forums/topic/page-header-filter-id-inside-function-generate_page_header_get_options/

    #491833
    vr51

    Thank you, Tom. Looking forward to building with GPP 1.6.

    #491834
    Tom
    Lead Developer
    Lead Developer

    Just merged it with 1.6, so it’ll be there.

    This will be the usage:

    add_filter( 'generate_page_header_id', function( $id ) {
    	if ( is_page( 'about' ) ) {
    	 	return 17686; // ID of the Page Header to use.
    	}
      
      	return $id;
    } );
    #491858
    vr51

    This is why I like GeneratePress!

    Will keep a copy of this snippet. Thank you so much.

    #492330
    Tom
    Lead Developer
    Lead Developer

    No problem! 🙂

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