0

I am using Easy Content Types for a custom post type and metabox with several fields including one called ecpt_website.

I have a custom page template which is outputting all of the fields nicely except for the ecpt_website field. the code generally looks like this for each field:

if(!empty ($ecpt_company)) {                     
        echo '<div class="co">';
            $content = apply_filters( 'the_content', $ecpt_company );
            $content = str_replace( ']]>', ']]&gt;', $content ); 
        echo '<span class="cbt-label">Company: </span>'. $content.'</div>'; 
} 

That will display something like Company: Example Company

The code for ecpt_website is similar and should output Html that looks like this:

<div class="website"><a href="http://www.example.com/" target="_blank"><span class="cbt-label">Website: </span>www.example.com</a></div>

The problem is that while every other field is working. The website url field is outputting a lot of extra code that looks something like this:

<div class="web"><a href="<blockquote class="wp-embedded-content" data-secret="qaxc7Sae67"><a href="https://www.example.com/">Home</a>
</blockquote>
<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);" src="https://www.example.com/embed/#?secret=qaxc7Sae67" data-secret="qaxc7Sae67" width="500" height="282" title="&#8220;Home&#8221; &#8212; Example Company Info Center" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
" target="_blank"><span class="cbt-label">Website: </span>
<blockquote class="wp-embedded-content" data-secret="qaxc7Sae67"><a href="https://www.example.com/">Home</a></blockquote>
<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);" src="https://www.example.com/embed/#?secret=qaxc7Sae67" data-secret="qaxc7Sae67" width="500" height="282" title="&#8220;Home&#8221; &#8212; Example Company Info Center" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</a></div>

I fixed it by using this code - ie. I removed the apply_filters:

if(!empty ($ecpt_website)) {        

        echo '<div class="website">';
        echo '<a href="'.$ecpt_website . '" target="_blank">';               
        echo '<span class="cbt-label">Website: </span>'. $ecpt_website;
        echo '</a>';
        echo '</div>';
         } 

Do you have any idea why this happens? I looked up apply_filters and couldn't find anything similar to what I am experiencing.

1

apply_filters is a function used all throughout WP in many different contexts, your issue here is the specific filter you are applying, which is the_content.

the_content filter by default runs on the main post content field, and does all sorts of transformations via a number of hooked functions: wptexturize, convert_smilies, wpautop, do_shortcode, shortcode_unautop, prepend_attachment, wp_make_content_images_responsive.

In your case, the markup is an embed automatically generated by WordPress when an embeddable URL is encountered within the content.

It doesn't make sense to use the_content filter in the case of your URL field, you should just use esc_url instead:

echo '<a href="' . esc_url( $ecpt_website ) . '" target="_blank">';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.