• Resolved Rahul DC

    (@rahuldc)


    My theme offers a different style for embeds when I paste my link directly. See the pic below.
    Theme default link

    But WordPress Oembeds keep overwriting my theme style in 2 secs to the iframe as you know.
    Wordpress default

    How can I disable just the wordpress but not my theme. I tried this plugin but it disabling everything and just giving a plain text of the link I pasted. Any tweak to just diable wordpress not restrict my theme?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Rahul DC

    (@rahuldc)

    I just found both are wordpress styles…. 1st one from different version unless I am wrong, but I like it not this iframe. how can I fix it ?

    • This reply was modified 8 years, 2 months ago by Rahul DC.
    Plugin Author Pascal Birchler

    (@swissspidy)

    Hey there,

    What you see in these screenshots is absolutely correct and hasn’t much to do with your theme and nothing to do with different WordPress versions. I’ll try to explain it to you:

    Embeds are simple <iframe> tags with some JavaScript. As a fallback for when JavaScript is not available or not yet loaded, a <blockquote> is shown. As soon as the JS is loaded, the <blockquote> gets replaced by the <iframe> (which loads the content from the embedded site). That’s why the output changes after ~2s in your example: the JavaScript is being loaded.

    Yes, the <blockquote> has some styling thanks to your theme, but the <iframe> will always be in the style of the embedded site. That’s how iframes work.

    Of course one can remove the <iframe> and only show the <blockquote>, though I don’t see a compelling use case for that. Here’s how you could do it:

    // Remove oEmbed-specific JavaScript
    remove_action( 'wp_head', 'wp_oembed_add_host_js' );
    
    /**
     * Only allow blockquotes
     */
    function custom_filter_pre_oembed_result( $result, $data, $url ) {
    	if ( false !== strpos( $result, 'wp-embedded-content' ) ) {
    		$allowed_html = array(
    			'a' => array(
    				'href' => true,
    				),
    				'blockquote' => array(
    					'class' => true
    				),
    		);
    
    		return wp_kses( $result, $allowed_html );
    	}
    
    	return $result;
    }
    
    add_filter( 'pre_oembed_result', 'custom_filter_pre_oembed_result', 11, 3 );

    Note:

    This code is untested. You need to disable this plugin for this code to work.

    Thread Starter Rahul DC

    (@rahuldc)

    Thanks for the response. I hate to uninstall it but I really love the blockquote.

    And thanks for giving the code even though I have to disable this plugin. Just 1 thing, Where do I place the big code you given?

    • This reply was modified 8 years, 2 months ago by Rahul DC.
    Plugin Author Pascal Birchler

    (@swissspidy)

    Oh, sure. You can either put this into your theme’s functions.php file or — preferably — in a custom plugin.

    A plugin is essentially a PHP file in your wp-content/plugins/ folder that needs a header comment at the beginning. It would look something like this:

    <?php
    <?php
    /*
    Plugin Name: Disable Embeds Iframes
    Plugin URI:  https://www.ads-software.com/support/topic/how-do-i-disable-just-wordpress-feature-but-not-my-theme-style/
    Description: Remove the iframes, keep the blockquotes.
    Version:     20160913
    Author:      Rahul DC
    Author URI:  https://profiles.www.ads-software.com/rahuldc
    */
    
    /* insert code from before */
    

    Save this as disable-embed-iframes.php or something like that. Activate in the admin after uploading to your server.

    Alternative: Simply create blockquotes in the editor yourself ??

    Thread Starter Rahul DC

    (@rahuldc)

    I have a custom functions plugin already in use. I pasted your code and it worked like a charm. This is fantastic. Thank you so much.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do I disable just wordpress feature but not my theme style’ is closed to new replies.