• Resolved screener

    (@screener)


    Hello all,

    When I try to post this:
    my link

    The post ends up as:
    my link

    How can I stop WP from swallowing the data-timestamp=”2.16″ portion?

    Thanks,

    ted

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter screener

    (@screener)

    adding asterisks to try to fool the editor …

    When I try to post this:
    *<*a class=”post-handle” href=”#” data-timestamp=”2.09″*>*my link*<*/a*>*

    The post ends up as:
    *<*a class=”post-handle” href=”#”*>*my link*<*/a*>*

    How can I stop WP from swallowing the data-timestamp=”2.16″ portion?

    Thanks,

    ted

    Depending a the user’s permissions, WordPress will whitelist certain html elements and attributes and then remove those elements/attributes not found in the whitelist before it saves to the database.

    To add a “data-timestamp” attribute to an anchor (link) tag try adding this code to your theme’s functions.php:

    function add_data_timestamp_attribute_to_anchor( $tags, $context ) {
            if ( 'post' !== $context && ! in_array( 'post', $context ) ) {
                    return $tags;
            }
    
            $tags['a']['data-timestamp'] = true;
    
            return $tags;
    }
    add_filter( 'wp_kses_allowed_html', 'add_data_timestamp_attribute_to_anchor', 10, 2 );

    PS To have your code appear as text you need to surround the code with a “backtick” mark on each side (press the code button on top of the textarea to add one automatically).

    Thread Starter screener

    (@screener)

    ended up using the solution here.

    Thread Starter screener

    (@screener)

    Fair notice, I actually went back to jkovis’ solution, “add_data_timestamp_attribute_to_anchor”. Thank you again to jkovis.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘link is being stripped, how to stop?’ is closed to new replies.