Support

Account

Home Forums General Issues How to create Subtitle for each post with ACF

Solving

How to create Subtitle for each post with ACF

  • I am trying to create subtitle custom filed with ACF, but not sure from where to start.

    could you please help

  • Please check attachment:

    I have completed it on ACF, now i need few lines to put on function.php to make it work on UI.

    Please help

  • What you need to do is edit your template where the title of the post is displayed and add something like

    
    <h1><?php the_title(); ?></h1><!-- this should be somewhere in your templates -->
    <?php 
      if (get_field('subtitle')) {
        ?><h2><?php the_field('subtitle'); ?></h2>
      }
    ?>
    
  • it didn’t call correctly

  • You can’t put PHP code in the content of the post. You need to edit the php template file. If you want to put basic fields into the content editor then see this https://www.advancedcustomfields.com/resources/shortcode/

  • I am lost what you are talking about.

    i thought below command which you gave – will work as variable.

    if (get_field(‘subtitle’)) {
    ?><h2><?php the_field(‘subtitle’); ?></h2>
    }
    ?>

    In previous screen – i put subtitle as “This is subtitle” on subtitle field when creating a post, but when i visit the post – post has code above screenshot code instead of “This is subtitle”

    It meant which code you gave is not calling ‘subtitle’ field to display in front-end?

  • The code I gave you was to put in your template file. The template file would located on your site in the theme folder for your theme. In order to use the code you must edit the file.

    From what it looks like you put the code into the “Content” WYSIWYG editor for the page. PHP code cannot be edited there. This is why I gave you the link to the shortcode documentation for ACF.

    At this point I can’t help you because I don’t understand what it is you’re trying to accomplish or where you’re trying to accomplish it. You’ll need to provide more information with a few more details.

  • Yes, i put in theme file – under this line:

    <?php the_title( ‘<h1 class=”entry-title” ‘ . hybrid_get_attr( ‘entry-title’ ) . ‘>’, ‘</h1>’ ); ?>

    ….. put your code here….

    now for your below comment:

    “From what it looks like you put the code into the “Content” WYSIWYG editor for the page. PHP code cannot be edited there. This is why I gave you the link to the shortcode documentation for ACF.”

    Your understanding is wrong.

    now let me tell you what i did.

    ****

    1. Install ACF
    2. Create Group – check screenshot.
    3. Put your code in single-content.php under the same line that you are talking.
    4. Create new post – new post has option to put the value for subtitle.
    5. I put “This is testing subtitle”
    6. Published the post.

    Now, post has the code as subtitle instead of what i put in subtitle field.

    Please give me correct code, so that i have put on subtitle field that value in the post.

  • Thanks for the details. If this does not work then you need to talk to the people that created the theme that your using to find out the correct way to modify templates and add content to them…

    I did miss a php tag in my original code, try this

    
    <?php the_title( '<h1 class="entry-title" ' . hybrid_get_attr( 'entry-title' ) . '>', '</h1>' ); ?>
    
    <?php 
      if (get_field('subtitle')) {
        ?><h2><?php the_field('subtitle'); ?></h2><?php 
      }
    ?>
    

    It would help if you use code tags for inserting code here, there’s a code button in the toolbar.

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

The topic ‘How to create Subtitle for each post with ACF’ is closed to new replies.