Insert custom field between post data in Upfront

Using Custom Press to create some custom fields. I want any post that I create to have the custom field because I have added it in the builder.
Is it possible to automatically insert the custom field between content(like inside paragraph of post data element) in post data element for a newly created post in upfront editor.

  • Predrag Dubajic

    Hi Juan,

    Hope you're doing well.

    This is not something possible with the builder itself and we will need to use jQuery here.

    The thing is that jQuery is fired in browser and PHP is on server so we can't add the shortcode directly via jQuery and there are some extra steps required.

    First thing to do is start Upfront Builder, edit single post layout, and add text element after the post content, and add new preset for that element.
    We will use that preset name as a class later on in jquery so remember the name you used.

    In other tab go to CustomPress custom fields, click on Embed Code for that custom field and copy the shortcode with setting up the attribute you want to show, it would look something like this:
    [ct id="ct_tester_text_89bb" property="value"]

    Add that shortcode to your text field in Builder.

    Now when you check the post it will load that element after the content so now we can apply the jquery to move it around.

    You can do that by adding this code as mu-plugin:

    function add_custompress_shortcode_before() { ?>
    	<script type="text/javascript">
    		jQuery( document ).ready(function() {
    		    jQuery( '.PRESET_NAME' ).prependTo( jQuery( '.upostdata-part .upfront-indented_content > p:last-of-type' ) );
    <?php }
    add_action('wp_footer', 'add_custompress_shortcode_before');

    In that code you will just need to replace PRESET_NAME with the name of the preset you used for the text element.

    Reload the post on frontend and you should see it loaded before the image.

    Best regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.