how do you use the attributes in custompress?

I have been trying to style my custom fields in custompress when i noticed that there attributes & id's that can give me some more option in this area (i think). I also would like to make a link and the ability to use some html in a custom field.

Would i be able to accomplish this or will it take extensive coding to make it happen?

  • aecnu

    Greetings majaluk,

    Thank you for the great question.

    I also would like to make a link and the ability to use some html in a custom field.

    Would i be able to accomplish this or will it take extensive coding to make it happen?

    From what I am understanding you want to allow html In the "Field Type" in the custom field section.

    I believe this was intentionally excluded for security reason just like raw html in WordPress is excluded except for admins.

    However, since I am in fact not the lead developer of Custom Press and that I do not know everything, I think we should get an opinion from the reigning authority Arnold on this subject.

    Therefore I will see if I can get the lead developer Arnold in here with his invaluable insight into this plugin for his advice/advise for us.

    Though this may take a bit longer then a normal ticket, I will try to get him in here asap.

    Cheers, Joe

  • Arnold

    Custom fields were intended to store data so it couldbe used any place that data is needed. If you start putting you a bunch of html around it IN the field your overcomplicating that and creating security problems. You are also depending on the person doing the input getting it right. Since it was intended to be simple we don't do it.

    However you can always wrap a given shortcode for a field with whatever HTML you want either in the template or in a post.. For example in a template you coulddo things like.

    <span class="my-class">
    <?php echo do_shortcode('[ct id="_ct_selectbox_4cf582bd61fa4""]'); ?>
    </span>

    We've had some people use this kind of thing to create maps from a set of custom address fields.

    You can also use add_filter to add wahtever you want to a given custom fields output. There are three filter

    $result = apply_filters('ct_shortcode', $result, $atts, $content);
    $result = apply_filters('tax_shortcode', $result, $atts, $content);
    $result = apply_filters('custom_fields_shortcode', $result, $atts, $content);

    Where $result is the normal output of the shortcode,
    $atts is the set of attribute passed to the shortcode,
    $content is the incoming content of the meta field.

    With that you can completely override how the shortcodes work and be specific down to the individual field id.

  • Arnold
    <?php
    add_filter('ct_shortcode', 'my_filter'); //add the filter
    function my_filter($result='', $atts=null, $content=null){
      //Extract the attributes $id will have the custom field id
      extract( shortcode_atts( array(
      'id' => '',
      'property' => 'value',
      ), $atts ) );
    
      $output = '';
    
     if($id == 'my_custom_field_id'){ // only change the field you want
        $output .= '<h2>'; // add what you like to the result
        $output .= $result //the output from the shortcode
        $output .= '</h2>';
        return $output; // return the changed result
      }
      return $result //return the unchanged result
    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.