Support

Account

Home Forums Backend Issues (wp-admin) how to add my custom fields in functions.php

Solving

how to add my custom fields in functions.php

  • Hello, I have some custom fields that I would like to add within the content of the post through a tag, when writing the tag within the content it is replaced by my custom fields

    my idea is basically to do the following in functions.php:

    add_filter (‘the_content’, ‘function_name’);
    function function_name ($content) {
    if (have_rows (‘group_fields’)):
    while (have_rows (‘group_fields)): the_row ();
    $ title = get_sub_field (‘title’);
    endwhile;
    endif;
    $ new = str_replace (“<!–tag_name–>”, “<div> $ title </div>”, $ content);

    return $ new;
    }

  • Have you tried this and it is not working?

    If you enter this into the editor

    
    <!--tag_name-->
    

    WP will convert it to this

    
    <!-tag_name->
    

    If it’s not working it is probably because your replace id incorrect. The WP editor can to strange things to comments depending on how and in which mode they are being entered. This is why shortcodes are generally used for this type of thing.

  • I’ve tried editing the above several times, I can’t event get the proper code to stick here using code tags.

    Remove all the spaces from this to see what WP converts it to

    
    & lt;-tag_name-& gt;
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘how to add my custom fields in functions.php’ is closed to new replies.