The WordPress and the vanishing html elements

Are you looking for a solution to any of the following probelm

"html elements are not working in wordpress post",
"iframe tag is getting stripped in the post after update",
"script tags are vanishing after updating the post",
"not able to use any html elements in the post"
"Not able to insert script into wordpress post"

Cause, I have been there too and found the following solutions to be useful.

There are so many solution you might have stumbled upon while searching for a fix to this issues. Yes I did too.

Here are some of them I found to be working like a charm.

Solution 1:

Script n Styles Plugin :

There are so many plugins I have tried and I found this one to be meeting the objective of  its creation.

you can apply scripts and styles globally at every page, It allows you to write various flavours of  CSS and Java Script and also enables you to control where to add the script/style, in the header, or body etc.

screen-shot-2017-12-03-at-11-48-43-am

screen-shot-2017-12-03-at-11-52-53-am

 

Solution 2:

Shortcoder Plugin

you can write CSS, Javascript, HTML and create a shortcode and use it in your post

 

screen-shot-2017-12-03-at-4-12-17-pm

Copy the shortcode given, into the post (or) page where you want this code.

screen-shot-2017-12-03-at-4-13-45-pm

Thats it. the result will be perfect.

screen-shot-2017-12-03-at-4-15-41-pm

Solution 3

In case if you have constraints that you cannot install the plugin for performance reason and wanted to do it without plugin. I would recommend creating the shortcode by yourself. Yes we can create shortcode without any plugin.

In order to do that you should be having access to the hosting FTP as it has to be done in the configuration file level.

wp-content/themes/<your-themename>/functions.php

all we have to do is the following

  • Add the html/script code that you want to add into the variable
  • Return it inside the function
  • Assign the function to short code using add_shortcode function

here is the sample

<?php
add_shortcode('pagetitle','titlecode');
function titlecode(){
$outhtml='
<script>
jQuery(document).ready(function(){
        jQuery("#pagetitle").css("color","tomato");
}); 
</script>';
return $outhtml;
}
?>

Now we can use the shortcode in our page and test.

screen-shot-2017-12-03-at-6-11-09-pm

 

Hope it helps.

Cheers

A K S A R A V