• Resolved Loekarin

    (@loekarin)


    I have installed the KIA subtitle plugin. I use the GeneratePress theme. I read the FAQ about ‘how do I display the subtitle in my theme’ and ‘where do I add this code?’.
    Unfortunately, I need some help here.

    In the content.php file I have added the code like this:

    [some code before this]
    */
    do_action( ‘generate_before_content’ );
    ?>

    <header class=”entry-header”>
    <?php
    /**
    * generate_before_entry_title hook.
    *
    * @since 0.1
    */
    do_action( ‘generate_before_entry_title’ );

    the_title( sprintf( ‘<h2 class=”entry-title” itemprop=”headline”>‘, esc_url( get_permalink() ) ), ‘</h2>’ );

    if( function_exists( ‘the_subtitle’ ) ) the_subtitle( ‘<h3 class=”subtitle”>’, ‘</h3>’ );

    /**
    * generate_after_entry_title hook.
    *
    * @since 0.1
    *
    * @hooked generate_post_meta – 10
    */
    do_action( ‘generate_after_entry_title’ );
    ?>
    </header><!– .entry-header –>

    <?php
    /**
    * generate_after_entry_header hook.
    *
    * @since 0.1
    *
    * @hooked generate_post_image – 10
    */
    do_action( ‘generate_after_entry_header’ );

    [some more code after this]

    But this is not working. So, what do I do wrong?

    • This topic was modified 4 years, 5 months ago by Loekarin.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author HelgaTheViking

    (@helgatheviking)

    Other than the funky copy/paste job on the ‘ and ” what you have looks right. Maybe double check that your code isn’t using curly quotes and double-check that you’ve actually got a subtitle saved for the post you are looking at.

    If your theme has hooks like this I would probably use one of those instead of editing the template. You could add this snippet to your child theme’s functions.php

    
    function kia_add_subtitle_to_generate_press() {
    	if ( function_exists( 'the_subtitle' ) ) {
    		the_subtitle( '<h3 class="subtitle">', '</h3>' );
    	}
    }
    add_action( 'generate_after_entry_title', 'kia_add_subtitle_to_generate_press', 5 );
    

    Hope that works for you.

    Thread Starter Loekarin

    (@loekarin)

    thank you for your answer. I’m not a developer and not experienced with PHP, so I need some help.

    1) currently I don’t have a child theme. This is the only php I need to add.
    I looked at the GeneratePress site and there I read:
    “However, if all you’ll be doing is adding CSS or PHP, a child theme probably isn’t necessary. See our Adding CSS and Adding PHP articles.”

    2) I read about Adding PHP
    They refer to the Code Snippets plugin.

    3) do you recommend to use the Code Snippets Plugin?
    Code Snippets Plugin

    if so, what is the code snippet that I should add?
    the one that you posted above?

    Thread Starter Loekarin

    (@loekarin)

    in addition: where do you see clunky ‘ and ” ?
    Maybe I’m looking over it, because I don’t see where I mistyped or miscopied…

    Plugin Author HelgaTheViking

    (@helgatheviking)

    https://share.getcloudapp.com/nOueWXKL
    All your quotes are curly quotes… though it looks like your entire code block has them. I suspect it’s how the forum is displaying them since you aren’t formatting it as code.

    <div id=”test”>Test</div>

    versus

    <div id="test">Test</div>

    I disagree with GeneratePress… if you are editing a template or adding a single PHP snippet to functions.php then you need a child theme… otherwise you can never update GeneratePress. The exception is unless, you use the Code Snippets plugin. My first choice is always child theme, but I frequently recommend Code Snippets to users like yourself who aren’t as comfortable with development stuff.

    The code snippet I posted above would be the same either in a a child theme’s functions.php or in the Code Snippets plugin.

    Thread Starter Loekarin

    (@loekarin)

    about the curly quotes…
    actually, I see this in your documentation as well, in how do I display the subtitle in my theme

    the code I copied has single and double quotation marks
    see image

    Plugin Author HelgaTheViking

    (@helgatheviking)

    single and double quotes, yes, but those aren’t curly quotes in the docu.

    See my previous message for an example of the distinction.. it’s slight:
    https://share.getcloudapp.com/d5uWb2zK

    Thread Starter Loekarin

    (@loekarin)

    Indeed, that’s really slight.. I didn’t notice it at first.
    I wonder if this is just a font issue. On my keyboard there’s just a ” button,
    which I use.

    But I’m going for the child theme option first. I’ll let you know if this works.

    and a minor remark, mostly for myself, is that I think generatepress is written as one, and not like ‘generate_press’
    but that’s easy testing using your code snippet

    • This reply was modified 4 years, 5 months ago by Loekarin.
    • This reply was modified 4 years, 5 months ago by Loekarin.
    Thread Starter Loekarin

    (@loekarin)

    just to let you know: I added the code snippet to the child theme’s function.php
    and this works.
    (writing ‘generatepress’ and not ‘generate_press’ )

    Thank you very much for your help!!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to add code to GeneratePress theme?’ is closed to new replies.