• Hi,

    First of all, I am new to WordPress.

    After creating and activating a child theme for my template, I would like to edit the html in the content of the static front page. More specifically, I would like to add an anchor to one of the sections, after people click on the CTA Button on top of the page. Previous anchor posts mostly relate to simple links inside of the post, thats why I ask this question.

    Where can I edit the html for inserting an anchor into the H2 title? Or, more generally, how do you find the right file in your theme fast to grab and modify the specific html code? I hope this can help other beginners too.

    Many thanks in advance,
    Christian

Viewing 8 replies - 1 through 8 (of 8 total)
  • Look for the file front-page.php in the theme files. Will be right in wp-content/themes/your-theme, where your-theme would be your theme name.

    Copy front-page.php into your child theme folder.

    Provided you’ve set up your child theme correctly and your theme is using the file front-page.php for it’s homepage template, you can make whatever changes you’d like to the file front-page.php in your child theme folder.

    Here’s a great resource regarding template hierarchy in WordPress. https://developer.www.ads-software.com/themes/basics/template-hierarchy/

    Myles
    [signature moderated as per forum rules]

    Thread Starter carokross1986

    (@carokross1986)

    Hi Bijingus,

    many thanks for your reply. I did open front-page.php before and found a piece of code referring to section header and subtitle:

    # Theme Section Args
            $section_title = mt_get_page_option(get_the_ID(), 'section-heading-title');
            $section_subtitle = mt_get_page_option(get_the_ID(), 'section-sub-heading-title');

    This probably means a referral to another file as there is no H2 Heading Code in the whole file.

    How can I locate the H2 code? (Also with inspect function of chrome maybe.)

    Many thanks,
    Christian

    Edit: I found it. Thank you for the link especially, this chart was a great help.

    Christian

    Thread Starter carokross1986

    (@carokross1986)

    I cannot close this topic by editing the post, so I write another thank you.

    No Problem, glad I could help.

    Thread Starter carokross1986

    (@carokross1986)

    One more question related to this topic (one door closes, another ten open).

    I want to put the anchor id for the H2 heading of first section on the homepage.

    if ( $section_title != '' || $section_subtitle != '' ) {
                echo '<div class="container">';
                    echo '<div class="row">';
                        echo '<div class="col-xs-12">';
                            echo '<div class="section-info">';
                                if ( $section_title != '' ) {
                                    echo '<h2>'.$section_title.'</h2>';
                                    echo '<hr>';
                                }
                                if ( $section_subtitle != '' ) {
                                    echo '<p>'.$section_subtitle.'</p>';

    Obviously, if I put it into the H2 code, all titles get this anchor. Since I have never worked with php before, I don’t know where to put the anchor id into the specific section.

    Thanks you very much,
    Christian

    Thread Starter carokross1986

    (@carokross1986)

    Problem: Put Anchor to the second section of the page, so when people click on CTA on top, they get to the second section.

    My thinking is to copy those three lines below and put in a specific title:

    if ( $section_title != '' ) {
                                    echo '<h2>'.$section_title.'</h2>';
                                    echo '<hr>';

    Can somebody help out?

    Thanks a lot,
    Christian

    I think I understand what you are asking. This should do the trick.

    if(is_front_page()) {
      echo '<h2><a id="your-id" href="your-link">' . $section_title . '</a></h2>';
    } else {
      echo '<h2>' . $section_title . '</h2>';
    }
    echo '<hr>';

    This will only include your link if the page is your front page. Make sure you’ve set the appropriate page as the front page in the customizer though.

    Also, you’ll have to replace the anchor id and href with your own.

    Hope this helps.

    Myles

    Thread Starter carokross1986

    (@carokross1986)

    Hi Myles,

    thanks so much for your answer. I have several H2 header on my front page. Would this relate to all sections on the front page that carry an H2 header?

    I am not sure how to implement: Put it in with an if / else statement or
    simply overwrite the code?

    Edit: I understood your code now, you put an else statement inside. Still does it run for all H2s on the front page as I would just let the user click on the top CTA button to get to the second of four sections?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Theme Regina] Edit HTML / Add Anchor to title section’ is closed to new replies.