Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1200519

    Hi,

    I use a custom page template with Enfold and ALB. That works fine. Now I want to add a custom field via ACF Plugin which is in general also no problem and already working in another place.

    Now I would like to add the value of that field right below the title of the page.

    The code looks like this:
    <div class="hersteller"><?php the_field('hersteller'); ?></div>

    How am I supposed to do that? Do I need to create a new template and insert the code there? Could you give me some hints?

    Thanks
    Dennis

    • This topic was modified 4 years, 8 months ago by Dennis.
    #1200756

    Hey dennsen,

    You should be able to use a hook for that, please try this in your functions.php file:

    function add_below_page_title(){
    YOUR CODE GOES HERE
    }
    add_action('ava_after_main_title', 'add_below_page_title');

    Best regards,
    Rikard

    #1201182

    Hi Rikard,

    Has the code to look like that?
    echo "<div class='hersteller'><?php "the_field('hersteller');" ?></div>";

    Thanks
    Dennis

    #1201475

    Hi Dennis,

    I’m not sure, if that doesn’t work then please try this instead:

    echo "<div class='hersteller'>" . the_field('hersteller') . "</div>";

    Best regards,
    Rikard

    #1203630

    Hi Rikard,

    I changed the code slightly for me to work best:

    function add_above_page_title(){
    ?>	
    	<div class="herstellerProdukt"><?php the_field('hersteller'); ?></div>
    <?php	
    }
    add_action('ava_after_main_container', 'add_above_page_title');
    ?>

    That is working fine now. I have the correct field above the title on a product page, see here:
    https://www.itraco.ru/goods/%d0%bf%d0%be%d0%b2%d0%b5%d1%80%d1%85%d0%bd%d0%be%d1%81%d1%82%d0%bd%d1%8b%d0%b5-%d0%bc%d0%b0%d1%82%d0%b5%d1%80%d0%b8%d0%b0%d0%bb%d1%8b-3/

    Unfortunately I also see that field on a category page, like here:
    https://www.itraco.ru/goods_category/%d0%b1%d1%83%d0%bc%d0%b0%d0%b3%d0%b8-%d1%80%d1%83%d0%bb%d0%be%d0%bd%d0%bd%d1%8b%d0%b5/

    How can I exclude this from every other type of page except my cpt “goods”?

    Thanks for your help!
    Dennis

    #1204289

    Hi Dennis,

    I’m not sure if this will work, but you need to check which the current post type is:

    function add_above_page_title(){
      if(get_post_type() = 'goods'){
    ?>	
    	<div class="herstellerProdukt"><?php the_field('hersteller'); ?></div>
    <?php
      }//end if	
    }
    add_action('ava_after_main_container', 'add_above_page_title');
    ?>

    Here’s the documentation for the function: https://developer.wordpress.org/reference/functions/get_post_type/. There might be a better function if you can’t get it to work.

    Best regards,
    Rikard

    #1204307

    Hi Rikard,
    Your hint led me to the final working code, which is:

    function add_above_page_title() {
    	if ( is_singular( 'goods' ) ) {
    	?>	
    	<div class="herstellerProdukt"><?php the_field('hersteller'); ?></div>
    	<?php	
    	}
    }
    add_action('ava_after_main_container', 'add_above_page_title');
    ?>

    Thanks for your help! Topic can be closed.

    Best regards,
    Dennis

    #1204801

    Hi Dennis,

    Great, I’m glad that you found a solution and thanks for sharing. I’ll close this thread for now then, please open a new thread if you should have any further questions or problems.

    Best regards,
    Rikard

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Add code after page title’ is closed to new replies.