Support

Account

Home Forums General Issues ACF Gallery & ACF Alt Text Reply To: ACF Gallery & ACF Alt Text

  • 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');