• 07-11-2018, 16:54:58
    #1
    Arkadaşlar elimde böyle bir kod var, yazı içinde değişiklik yapıyor fakat iletişim ve hakkımızda gibi olan sayfalardada content'i değiştiriyor. Bunun sadece post'ta değişiklik yapması için ne yapmam gerekiyor. Php bilen arkadaşlar yardımcı olabilirmi lütfen.

    function replace_content($content)
    {
    $search = array ($content);

    $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    $url = "https://www.site.com/video.php?x12345=".wp_strip_all_tags(get_the_conte nt());

    $url = str_replace("[player1]","",$url);
    $url = str_replace("[/player1]","",$url);


    $replace = array('<video class="video-js vjs-default-skin" controls preload="auto" width="100%" height="450" poster="'.$feat_image.'" data-setup="{}"><source src="'.$url.'" type=\'video/mp4\'></video>');

    $content = str_replace($search, $replace, $content);
    return $content;
    }

    add_filter('the_content', 'replace_content');
  • 07-11-2018, 17:10:23
    #2
    PHP - WORDPRESS - YAZILIM
    if ( is_singular( 'post' ) ) {
    add_filter('the_content', 'replace_content');
    }
    şeklinde çözüm olabilir diye düşünüyorum
  • 07-11-2018, 18:20:03
    #3
    function replace_content( $content ) {
    if( is_single() ) {
    $search = array( $content );
    
    $feat_image = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );
    $url = "https://www.site.com/video.php?x12345=" . wp_strip_all_tags( get_the_conte nt());
    
            $url = str_replace( "[player1]", "", $url );
            $url = str_replace( "[/player1]", "", $url );
            
            
            $replace = array( '<video class="video-js vjs-default-skin" controls preload="auto" width="100%" height="450" poster="' . $feat_image . '" data-setup="{}"><source src="' . $url . '" type='video/mp4'></video>' );
            
            $content = str_replace( $search, $replace, $content );
            return $content;
        }
    }
    
    add_filter( 'the_content', 'replace_content' );