Home Forums General Issues Where can I place the code?


Where can I place the code?

  • On f.e. I read about code you can use. But WHERE can I place this code? (Sorry, I don’t have experience with this.)

    I ‘m using WordPress 4.1.1 theme: Twenty Fifteen.

    Who can help me?

  • Ok, so you create the fields in the “Custom Fields” tab in the WordPress dashboard. If you have done this and created a field, it will yield a “value”. So if you create a field called “Home Text”, the value field will be home_text.

    When you create a rule for the “Home Text” to be shown on your “Home” page, then the fillable field will show on the Home Page dashboard.

    Once that is done, you need to call the field value within the template that is being used for the Home Page. Are you using a Home Page template or the default template?

  • So lets say you have a pretty generic Homepage Template

     *Template Name: Home
    <?php get_header(); ?>
    <?php the_field('home_text'); ?>
    <?php get_footer(); ?>

    If you place “the_field” php execution like above, your custom field will show within this template.

  • Thanks! Do I need to search for the Home Page via FTP and then to place the code via FTP?

  • No, are you familiar with WordPress templates? So, on the WordPress dashboard, go to your homepage editor. Pages > Home.

    On the right panel, where you can publish your page, you should see ‘Page Attributes’. That will tell you which template you are using for your homepage. Then go to Appearance > Editor > look for the template file that your page attribute for your homepage is using.

    This will show the code markup for your homepage template and you can place the <?php the_field('home_text'); ?> wherever in the code you want your field to render on the homepage.

  • So the only way to display ACF fields and values is modify the template? No way to do this in the post editor?

  • Well the whole point of ACF is to be able to add fields to the Page/Post Editor dashboard, so you don’t have to add to the content editor and your field will populate onto the page. So to answer your question, no…the snippets need to be added to the template.

  • Doesn’t that go against the easy way of creating the custom fields? I love how that is managed. Wish there was a simpler way for non-developers to add the fields to a page, post, etc. instead of modifying the PHP of the template. Unfortunately, I can’t get that to work either.

  • Well, it functions as an easy client-based custom-field software, where its easy to update a page(as a non-developer), once the fields are in place. I see what you mean though. If you want me to help you, email me at info@toolboxwebdesign.

  • @toolboxwebdesign, thank you very much for your answers. You really helped me with this.

    One more question: which file/template do I have to change when I want to display the added fields under the title of a post? I am using the standard template in WordPress 4.1.1 theme ‘Twenty Fifteen’.

  • You have to add it to content.php. The reason you add it here to add it to all your blog posts, is that it follows a hierarchy of templates to call the content.php into every blog post. It goes Main Index Template(index.php) > content.php. Meaning content.php is part of the Main Index Template.

    So if you want to add your field right under the title, go to content.php, and add your php snippet under a div tag classed “entry-content”. Just add it under that opening tag. 🙂

  • @toolboxwebdesign, thank you very much again. You solved my question very well!

  • I’m sorry, guys, I just don’t understand this at all. What actual code do I use? I only want to add the fields to portfolio/projects, not blog posts. Thanks for the help. I’m a designer living on the edge of developer, haha!

  • Hi Lt_Core, ok so you can place the custom fields on both pages and posts. So lets say you create a page “Portfolio”. Go into Custom Fields and create a new field. You can set a rule for your field that says it will show up on “Page” and your pages will show up in a drop down menu. Then choose Portfolio and your custom field will be on your “Portfolio” content editor page. As for the code. If you create a text field, then it depends on what you call it….but lets just say you call it Top Content. then the value will be top_content. Go to your Portfolio page and fill out your top_content field with your content. Then you need to go into the page template that you want the content to show up on and add the following code:

    <?php the_field('top_content'); ?>

Viewing 14 posts - 1 through 14 (of 14 total)

The topic ‘Where can I place the code?’ is closed to new replies.