Support

Account

Home Forums General Issues ACF Gallery & ACF Alt Text

Solving

ACF Gallery & ACF Alt Text

  • Hi there
    Sorry in advance I’m quite new to this and although I have a rough understanding of ACF I’m struggling with this issue despite reading a lot of the threads and documentation.

    I’m looking to introduce a gallery of 4 images on numerous pages whose alt text I would like to set in ACF. I already use ACF for simple text population with shortcodes inside WPBakery Theme. However, Im assuming this may need to be coded in manually, would anyone know how I would achieve this via WordPress?

    Any help would be greatly appreciated, although I’m now stuck in the house for the foreseeable future ive read everything I can and don’t seem to be getting anywhere.

    Thanks in advance

    Paul

  • If you’re using shortcodes to add ACF fields to pages then your going to need to build a custom shortcode which will require adding code to the theme’s functions.php file or possibly some other file depending on your theme.

    You can start here https://codex.wordpress.org/Shortcode_API

    There are some tutorials and guides available like this https://www.wpbeginner.com/wp-tutorials/how-to-add-a-shortcode-in-wordpress/ and this https://www.smashingmagazine.com/2012/05/wordpress-shortcodes-complete-guide/

    This is the basic shortcode code in ACF for a reference.

    
    /*
    *  acf_shortcode()
    *
    *  This function is used to add basic shortcode support for the ACF plugin
    *  eg. [acf field="heading" post_id="123" format_value="1"]
    *
    *  @type  function
    *  @since  1.1.1
    *  @date  29/01/13
    *
    *  @param  $field (string) the field name or key
    *  @param  $post_id (mixed) the post_id of which the value is saved against
    *  @param  $format_value (boolean) whether or not to format the field value
    *  @return  (string)
    */
    
    function acf_shortcode( $atts ) {
      
      // extract attributs
      extract( shortcode_atts( array(
        'field'      => '',
        'post_id'    => false,
        'format_value'  => true
      ), $atts ) );
      
      
      // get value and return it
      $value = get_field( $field, $post_id, $format_value );
      
      
      // array
      if( is_array($value) ) {
        
        $value = @implode( ', ', $value );
        
      }
      
      
      // return
      return $value;
      
    }
    
    add_shortcode('acf', 'acf_shortcode');
    
  • Hi John,

    Thanks for your response. I do use one or two shortcodes already within our theme and know how to edit the functions file however this is where knowledge ends and unsure on how to create a gallery referencing the alt tags using a shortcode.

    Kindest regards

    Paul

  • Not sure what you’re looking for. You would get values in the shortcode the same way you’d get them in when adding code to a theme like is discussed on the gallery field page https://www.advancedcustomfields.com/resources/gallery/

    The main difference is that you need to supply the post id of the post as is done by the built in ACF shortcode.

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

The topic ‘ACF Gallery & ACF Alt Text’ is closed to new replies.