-
AuthorPosts
-
April 3, 2020 at 2:00 pm #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, 7 months ago by Dennis.
April 4, 2020 at 7:26 am #1200756Hey 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,
RikardApril 6, 2020 at 10:55 am #1201182Hi Rikard,
Has the code to look like that?
echo "<div class='hersteller'><?php "the_field('hersteller');" ?></div>";
Thanks
DennisApril 7, 2020 at 5:24 am #1201475Hi 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,
RikardApril 14, 2020 at 3:46 pm #1203630Hi 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!
DennisApril 16, 2020 at 8:25 am #1204289Hi 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,
RikardApril 16, 2020 at 8:56 am #1204307Hi 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,
DennisApril 18, 2020 at 5:45 am #1204801 -
AuthorPosts
- The topic ‘Add code after page title’ is closed to new replies.