3

I have a page with certain html markup and element attributes as shown in the snippit below:

<ul class="accordion" data-accordion="">

When I edit the page as a user with the WP Administrator Role the <ul> remains intact upon page update. Perfect.

Yet when a user with WP Editor Role edits the page, the ul tag saves as follows:

<ul class="accordion">

Notice the data-accordion attribute is removed.

How can I get WordPress to retain markup tag attributes for users with the Editor role?

  • 1
    I think this has been answered here - wordpress.stackexchange.com/questions/188484/… – Edd Twilbeck Jul 22 '16 at 21:08
  • Thanks @EddTwilbeck, but that answer did not solve the specific problem I am encountering. My issue pertains to Editor role users not being able to retain certain html5 markup attributes while Administrator user can. – user98929 Jul 25 '16 at 18:15
  • Well it mentions KSES, which is the reason: it's HTML filtering that's applied to non-administrator users. You'll need to register data-accordion as an allowed attribute. And FWIW you've posted this as an answer when it should have been a comment on your question in reply to Edd's comment: since you haven't registered an account you'd need to come back here on the same browser (i.e. with the same login cookie) and you'd have permission to comment. – Rup Jul 25 '16 at 18:22
  • Please stop using answers for comments, really. That doesn't work and gets deleted. If you use same account as you started question with you can always comment in that thread. If you created multiple accounts by mistake you can request to get them merged. – Rarst Jul 25 '16 at 19:36
1

It is enough to add unfiltered_html capability to Editor role.

Add the following code into your current theme's functions.php:

function wpse_change_capability() {
    $role = get_role( 'editor' );
    if ( ! $role->has_cap( 'unfiltered_html' ) )
        $role->add_cap( 'unfiltered_html' );
}
add_action( 'init', 'wpse_change_capability', 10 );

Login as the user with Editor role. Test it by editing any post / page. HTML markup will be preserved. Remove the code above from functions.php.

If you decide to remove unfiltered_html capability from Editor role, repeat steps described above, using this code:

function wpse_change_capability() {
    $role = get_role( 'editor' );
    if ( $role->has_cap( 'unfiltered_html' ) )
        $role->remove_cap( 'unfiltered_html' );
}
add_action( 'init', 'wpse_change_capability', 10 );

protected by Community Jul 25 '16 at 19:34

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?