[Resolved] Add Class to Custom Field Shortcode

Home Forums Support [Resolved] Add Class to Custom Field Shortcode

Home Forums Support Add Class to Custom Field Shortcode

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1563994
    Vlidi

    Hi GP, and thanks for having such a great support forum.
    Almost all the questions I ever had re:GP are already answered in advance.
    Can’t get much better than this!

    I have managed to create and insert the Custom Field that adds the subtitle to the Post title via the Custom Field shortcode by modifying the solution Tom provided here (using Code Snippets):

    add_action( 'generate_after_entry_title', 'tu_after_featured_image', 15 );
    function tu_after_featured_image() {
      echo do_shortcode('[acf field="my_field_name"]');
    }

    The output works as it should, and now I have a few questions.

    1. How can I add the CSS class to this element so I can style the subtitles?

    2. Should I perhaps be using the Hook element for this instead?

    I have found this solution David proposed, but I am trying not to use a plugin, as Custom Fields seem to work.

    Thanks!

    #1564683
    Elvin
    Staff
    Customer Support

    Hi,

    I believe the shortcode you’re placing outputs a simple text?

    If so, you can wrap it in a <div class="your-class"> or <p class="your-class"> so you can target it properly.

    example:

    add_action( 'generate_after_entry_title', 'tu_after_featured_image', 15 );
    function tu_after_featured_image() {
      echo '<p class="your-class">'.do_shortcode('[acf field="my_field_name"]').'</p>';
    }

    With this, you can style the field output with “your-class” class.

    #1564712
    Vlidi

    Elvin, thank you very much.
    True, simple text it is, and this woks perfectly for the purpose.
    The support for GP is simply fantastic.
    Thanks once again!

    #1564717
    Elvin
    Staff
    Customer Support

    Glad it works for you. No problem. 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.