top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to add iframe into wp_insert_post in Wordpress?

0 votes
1,068 views

I am developing a wordpress portal. I am sending html content(youtube iframe) with ajax from frontend pages. But while I am inserting that post wp_insert_post removes iframe codes in it. There is no problem with ajax or somewhere else. I guess there is somekind of filter. How can I disable that and insert iframe code?

Code before inserting -> $_POST["content"]

<div class="line nVideo" style="text-align: center;" ><iframe id="player" type="text/html" width="650px" height="380px" src="http://www.youtube.com/embed/mY8BZsIgg74?showinfo=1&amp;enablejsapi=1&amp;color=white&amp;origin=http://432designstudio.com" frameborder="0" allowfullscreen=""></iframe></div><div id="empty-line" class="nText " ><div>gasdgdsag</div>

And after insertation i call content again -> get_post_field('post_content', $postID)

<div class="line nVideo" style="text-align: center"></div><div id="empty-line" class="nText "><div>gasdgdsag</div>
posted May 29, 2017 by Sahana

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

WordPress has wp_kses function to makes sure that only the allowed HTML element names, attribute names and attribute values plus only sane HTML entities will occur in $string. You have to remove any slashes from PHP's magic quotes before you call this function.

For your purpose you can try remove this filter by adding this code within your theme functions

function kses_remove_filters() {
    // Normal filtering
    remove_filter('title_save_pre', 'wp_filter_kses');

    // Comment filtering
    remove_filter( 'pre_comment_content', 'wp_filter_post_kses' );
    remove_filter( 'pre_comment_content', 'wp_filter_kses' );

    // Post filtering
    remove_filter('content_save_pre', 'wp_filter_post_kses');
    remove_filter('excerpt_save_pre', 'wp_filter_post_kses');
    remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
}

or Just use only

kses_remove_filters();
answer Jun 1, 2017 by Avijit Maity
Similar Questions
0 votes

I need to add a variable inside an array of an embedding gravity forms to populate 2 hidden fields: email and jobname.

Here is my code:

<?php 

    $email = get_field( "email_application" );
    $jobtitle = get_the_title();

    gravity_form( 5, false, false, false, array('email'=>'echo "$email";','jobname'=>'print "$jobtitle";'), false); 
?>

I know that echo, print or just the variable doesn't work as it show like this in my code:

<input name="input_6" id="input_5_6" type="hidden" value="print $jobtitle" class="gform_hidden" aria-invalid="false">

and

<input name="input_5" id="input_5_5" type="hidden" value="echo "$email";" class="gform_hidden" aria-invalid="false">

Instead I should get:

<input name="input_6" id="input_5_6" type="hidden" value="My job title" class="gform_hidden" aria-invalid="false">

and

<input name="input_5" id="input_5_5" type="hidden" value="myaddress@email.com" class="gform_hidden" aria-invalid="false">

Can someone could point me in the right direction.

Thank you.

0 votes

I have Wordpress site and I have incorporated Disqus into my posts but I am not sure how to add them to my pages. Any help will appreciated?

0 votes

I building a website on Wordpress. When I add this below code

$(document).ready(function() {  
$('#readerareaimg img').each(function(){
var filename = $img.attr('src')
$img.attr('title', filename.substring((filename.lastIndexOf('/'))+1, filename.lastIndexOf('.')));
$img.attr('alt', filename.substring((filename.lastIndexOf('/'))+1, filename.lastIndexOf('.')));
});  

My website will generate alt and title tags automatically on images based on their file name, but I want to add any word or text before the file name. For example file name is phoneimg.jpg and it will display alt="phoneimg", but I want that alt to become alt="read phoneimg". How can I do this?

0 votes

I am making a custom plugin for wordpress and i need to create a page in the admin menu. I already have a file called menu_list.php with the following code:

function jps_mail_list_page_entry() {
add_menu_page(
    __('JPS Mailing List'),
    'JPS Mailing List',
    'manage_options',
    'jpsNews_mailinglist',
    'jpsNews_mailing_list',
    'dashicons-email'
);
}
add_action('admin_menu', 'jps_mail_list_page_entry');

function jpsNews_mailing_list() {
    echo 'hello';
}

Now, in the plugin page i have this:

function jpsNews_activate_plugin() {
    include_once(plugin_dir_path(__FILE__).'pages/mailing-list.php');
}
register_activation_hook(__FILE__,'jpsNews_activate_plugin');

Its not working. How can i do it?

+1 vote

I want my permalink to be accessable via more than one slug.

For example:
example-page.com/contact/1234 or example-page.com/contact-1234

...