There is a post type on my theme where a meta box is at the bottom of default body section. There is a “Add New” button at that metabox, when the button is being clicked a new section appears. I want the hidden section always being visible. I tried the javascript click()
function so that the button becomes auto-clicked.
These are the theme original codes:
echo '<a href="javascript:void(0);" class="option-tree-social-links-add option-tree-ui-button button button-primary right hug-right" title="' . __( 'Add New', 'option-tree' ) . '">' . __( 'Add New', 'option-tree' ) . '</a> ';
I tried the following codes but its not working:
echo '<a href="javascript:void(0);" class="option-tree-list-item-add option-tree-ui-button button button-primary right hug-right" title="' . __( 'Add New', 'option-tree' ) . '">' . __( 'Add New', 'option-tree' ) . '</a> <script>document.getElementsByClassName("option-tree-list-item-add option-tree-ui-button button button-primary right hug-right")[0].click(); </script>';
Need help!
Best option for you to add custom meta box for post
https://developer.wordpress.org/reference/functions/add_meta_box/
But if you want to use js, then use this