2

i have a problem with the posts of wordpress. Using the code embed function of an external blog publishing automatically on wordpress, the html code messes up my styling.

I do have the following code:

    <div class="entry-content">
     <div style="width:450px;margin:0 auto">
      <div style="position:relative;">
       <a target="_blank" href="DIFFERENT VARIABLES">
        <img width="???" alt="DIFFERENT VARIABLES" src="DIFFERENT VARIABLES" title="DIFFERENT VARIABLES" height="???" />
       </a>
      </div>
     </div>
     <p><br/>
     <div style="text-align:center"><small>SEVERAL <a>-TAGS</small></div>
    </div>

The goal is to get rid of the second <div> with the style attributes and to get rid of the <p><br/>.

The best way would be a function for the function.php cause I do have lo of posts.

Can anyone help me please? I'm good enough to do some html coding, but this is far beyond my skills.

2 Answers 2

1
function my_function($content) {
    $div = '<div style="width:450px;margin:0 auto">';
    // Make sure the offending div is there.
    if (strpos($content, $div) !== false) {
         // Remove div.
         $content = str_replace($div, '', $content);
         // Remove one ending div tag.
         $content = str_replace('</div>', '', $content, 1);
         // Remove the p, br.
         $content = str_replace('<p><br/>', '', $content, 1);
    }
    return $content
}
add_filter('the_content', 'my_function');

Add this to your functions.php.

Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried a jQuery command to remove it, such as jQuery('.entry-content br').remove() ?

At the php level, you could use the_content filter to change the contents.

1 Comment

Definitely don't use javascript for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.