Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress custom content area with wp editor?

Tags:

php

wordpress

Using my Wordpress theme functions file, I have created a custom meta text area (please see screenshot below).

The custom meta text area is displayed when editing a page.

enter image description here

It all works great saving and changing the text, but if i change a certain part of the paragraph text to heading2 and click save, it reverts the heading2 back to paragraph.

My functions update post meta box looks like the following:

if( isset( $_POST['my_meta_box_text_challengetbl'] ) )
    update_post_meta( $post_id, 'my_meta_box_text_challengetbl', wp_kses( $_POST['my_meta_box_text_challengetbl'], $allowed ) );
}

The $allowed php code looks like the following:

$allowed = array( 
    'a' => array( // on allow a tags
        'href' => array() // and those anchords can only have href attribute
    )
);
like image 459
Craig Avatar asked Feb 04 '26 18:02

Craig


1 Answers

Please update...

$allowed = array( 
    'a' => array( // on allow a tags
        'href' => array() // and those anchords can only have href attribute
    ),
    'h2' => array()
);

This will allow H2 to be used, note: you can add in any other html tags you want allowed here as well. Check out https://codex.wordpress.org/Function_Reference/wp_kses for more info.

like image 102
Simon Pollard Avatar answered Feb 06 '26 11:02

Simon Pollard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!