Wordpress - How to prevent stripping comments out of a template - html

I have a wordpress site that has to integrate with a .NET platform for a client. I simply need to add two commented out pieces of HTML for it to work on the .NET platform end (not our system).
Wordpress keeps stripping it out of the custom template, though. Is there a way around this?
Note: This is not done in the backend editor. This is directly in the template php file that I'm placing these two commented lines of code.
Also note: I already tried Linklays function to modify tinymce to see if that would be a solution, but again this isn't using tinymce since it's hard-coded into the template.

WordPress does no processing at all on any hard coded HTML in the templates, therefore I suspect you probably have some kind of caching plugin active which minified the html or strips out the comments.
Some themes have these caching methods build into them so if you have no caching plugin active it might be a good idea to view the documentation of your theme for any caching methods and related settings.
Maybe also worth looking at the commented code, If you added the code in a PHP block and used a keyboard shortcut to do the comment it might have added it as a PHP comment instead of a HTML comment.

For a comment in every page you can use the wp_footer hook. It will add your HTML to the footer of any page:
Here is the code rip you should add to your functions.php on your theme root directory, you can change it on your server or local project or via Administration Screens > Appearance > Editor:
add_action('wp_footer', 'some_comments');
function some_comments() {
echo '<!-- Write your comments here -->';
}

Related

wordpress site page not loading correctly

I am a noob to wordpress and not sure how to properly formulate my question, so I added a screenshot of the problem. When I navigate to the site below page is visible. It seems all Css and content is not being loaded properly.
When I click on one of the links the page loads correctly. The site does not have a valid SSL certificate atm and chrome does complain about that, but I never had it before that something like this happens.It doesn't seem to be a browser issue since I tried it on several different browsers.
I also cleaned up the .htaccess file to its default values. I have no idea where to start looking for a solution, any input would be great!
As I wrote in the comment, here is a possible fix to your problem. Put the code inside your functions.php file.
I'm not experienced using this CMS, but your problem seems to be related to the css and js resources loading.
Here and here there are some useful resource where you can find more info on how to handle your custom scripts in wordpress.
<?php
function init_res(){
// the wp_enqueue_style() function is used to load all the custom css files
wp_enqueue_style('scriptname', get_template_directory_uri().'/your/script/path/file.css');
// the wp_enqueue_script() function is used to load all the custom js files
wp_enqueue_script('scriptname', get_template_directory_uri().'/your/script/path/file.js', array('jquery') );
}
add_action('wp_enqueue_scripts', 'init_res');
?>
Note that with the javascript files, the wp_enqueue_script() function will take the array('jquery') param, this will tell to wordpress that the loaded script has the jquery dependency.

How do websites keep the header on every page if the header is in html?

So, I'm trying to make a website, but the problem is I can't find the most effective way to keep the header on every single page. My header is HTML code, and it is the most important source of navigation on the website. The tabs navigate using links to other HTML files (all located locally on my computer) and so every single new page is another separate HTML file. Here are the many different methods I used that all fell short in one way or another:
The most basic way: Copying the header code to EVERY HTML page on the website. I am currently using this method, and it is probably the most ineffective and stupid method ever. The downside (which is pretty obvious) is that not only is it tedious but every time I make a change to the header (like maybe add different menus, add another tab, change the image, etc.) I have to copy the new header code to everything else. That is ridiculous!!
I tried using the w3schools method of implementing a separate HTML file (with only the HTML code) onto the page HTML files. So, I have this 1 HTML file for the header that every page uses so I make a change in that one file and it automatically applies to everything else. However, it didn't let me organize the numerous HTML files effectively because unlike referencing a stylesheet like some file named 'style.css', it doesn't let me put the HTML sheet in a folder that doesn't share the same parent folder as the referencing HTML page files. Hopefully that made sense, but basically, I couldn't get a folder that separated the HTML menu tab files ("pages") and the HTML content files ("posts") without the w3school code failing. Here's the link: https://www.w3schools.com/howto/howto_html_include.asp
I've seen other options on Stackoverflow, like getting around the "can't implement HTML files" by using js files with html code in a document.write(), but this to me is very hard to use because of all my progress so far. Also, I am very uncomfortable with the idea of using document.write because it is probably still very different from a true html file. Seriously, why is there no HTML implementing system that stylesheets and scripts have??? (script src="b.js" script and link rel="stylesheet" href="css/style.css" type="text/css")
Using jQuery. I understand this the least (being an amateur programmer) but I've heard it isn't consistent either. It doesn't seem to work on a local file, and that sounds like a nightmare. Though, if there are good suggestions, having a jquery file tag along seems not the best solution but still a plausible solution.
So, I'm in great trouble. How do other websites do this? Do they use different files??? Do they use PHP files?? Am I going to have to scrap all my hard header HTML work and styling because PHP is another language?? Do I have to use Angular.js??? This is so complicated!
Hopefully, this question made some sense. Please ask if you have questions. Thanks in advance.
UPDATE
After checking numerous other posts on Stackoverflow suggesting PHP, I got my HTML files and then renamed it from "index.html" to "index.php", and holy macro it actually still behaved like an HTML file even if it wasn't!! Now I need to find a way to put:
include("header.php");
into my page PHP files that are actually in HTML code to reference a separate PHP file that has my header. How do I do that? Does it belong in like script tags or something? How do I add PHP code in a PHP file written in HTML code? Thanks for the answers to my previous question, I'm so sorry I should've read the answers on Stackoverflow more thoroughly first.
So I know it's been awhile since I asked the question and probably nobody cares anymore, but I just want to post an update after finding a solution to my question about using php code and how it all works.
First, I learned that in order for this to work, all my files had to be in php format. So I pulled up my folder of my local HTML files and literally just renamed it from something like "index.html" to "index.php". Then, without changing the HTML code, I opened it up in my browser and it was like nothing happened, except it was better! Now it can not only read HTML and style and script codes, but also php codes as well! I added:
<?php
include("header.php");
?>
to the top of my index.php file, for example, and then converted the rest of the files into php format like I did for this. I copied over my header html and css code and saved it in a separate php file in the same folder, and - there was no header. I was confused. What?? Why is it not doing anything? The header.php itself is working, why is the include function not??
Then, I learned that this php include code can't be executed on my local drive, so it doesn't work on my local drive but works when it is public and on a real website hosting service. I then installed XAMPP, which is a commonly used PHP development environment that is an Apache distribution and is totally free. It runs a sort of local hosting service that will support this php code and cause it to execute the way I intended it to. I'm sorry I'm not good at explaining how this works, as I just find it and use it. Anyways, XAMPP did make the php code included above actually do its job and I finally got the header-system I always wanted. Happily ever after, right?
Nope. Now that fundamental stuff is gone, I have to face other problems like formatting (a real pain in the a** considering how I have to find css problems in tons and tons of overlapping code), creating an entire personal search system (having to figure out how to make a php file actually use my brand new MySQL database, which is also run by XAMPP), and lots of other things. But, that sounds like a great adventure that I am willing and definitely eager to go through. Now, finally I am done blabbing for the day...I wonder how many hours of other people's time I just wasted.
Oh yeah..I forgot to mention, happy Fourth of July! (and happy birthday to the beloved Captain America)
Using JavaScript and jQuery is a very easy way to accomplish this. First, just build a sample JavaScript file. Inside, make functions that are run on page load. For example,
function buildPage() {
var html = ' ';
//Build the html through the function
//In the end...
$('html-id').empty().append(html);
}
This way each time the html is built you can just empty(clear whatever is in the id 'html-id') and then add your specific html. For example,
<html>
<head>Put header here!</head>
<body>
<div>Put tabs with onclick events here</div>
<div id="html-id"></div>
</body>
</html>
Each time a different tab is clicked, the buildPage() function should be called in order to build the page accordingly. No multiple html headers needed!
Write something like that
<html>
<head>
<title>First page</title>
</head>
<body>
<?php include ("header.php"); ?>
<!-- rest of your code -->
?php include ("footer.php"); ?>
</body>
</html>
It's recommended to do with that way. Wordpress is working like that too. Include files to main php file.
**Notice all your files have to be .php
Maybe this can help:
Include another HTML file in a HTML file
You can make one header.html and include it in all other html files of your website.

How do you work with include pages in jsp or php or the likes without getting IDE / Editor warnings for CSS classes?

If the CSS files for your site are referenced in the parent page, obviously you can use those CSS rules and classes in the sub-page or "included" page (like a jsp include or a php include). That will run as expected in the browser. BUT, if you are using an IDE or smart text editor of some kind (I'm using Netbeans), you will get warnings about the CSS elements in the sub-page (a .jspf for example) unless that file has a redundant reference to the css files. Is there a work-around for this? I don't want to have to reference the CSS files in both my jsp and my jspf (jsp include).
One technique I've used is to abandon jspf files in favour of a templating system where if you want to include something from a template, the template is actually a full page of which part is marked to be included. I actually use a home-grown template system for this, but my understanding is that thymeleaf (http://www.thymeleaf.org/) offers the same feature.

When coding a Wordpress theme, where does the theme (i.e. the presentation) end and the plugin (i.e. the functionality) begin?

The best guideline I have seen for what should be in a theme is to put "functionality" in a plugin.
I am looking at adding more "premium features" like jQuery image sliders. This requires a back-end user interface for selecting featured content to slide. Is this presentation?
How about shortcodes? A shortcode is a simple hook that enables you to call a PHP function by adding something such as [shortcode] to a post or page. I see this in themes all the time. Is it presentation?
I am unable to sort it out!
Keep most of the heavy lifting in your functions.php file and you should be fine. But don't be afraid to add functionality to your other theme files since PHP and WordPress rely heavily on the integration of function and presentation.
The functions.php file of your theme is basically that theme's "plugins." There is really no difference between what you can do with functions.php and what you can do with a plugin.
Reasons to create a plugin instead of embedding it into the functions.php file include wanting re-usability in other themes, or if the Theme didn't necessarily depend on the functionality and disabling the plugin was something you wanted to have as an option.
Reasons to use the functions.php instead of plugins include your themes dependency on the functionality to aide the presentation in some manner and therefore the theme would look wrong without it.

First widget works in Dashcode but not when deployed

My widget does not work once deployed even though it shows no errors in Dashcode. Apologies in advance for my inarticulartness with the terminology. I am a newbie.
To create the widget, I deleted the default .js file and pasted the JavaScript plus XHTML into the HTML page and created the accompanying CSS file.
The only code I can see that is generated is the plist.
I tried opening up all the permissions but nothing seems to change.
The OSX utilities console shows errors which are on lines beyond what there are numbers for in the code.
I don't think the JavaScript/XHTML/CSS is the problem as it works when in a web page and the widget does actually work within Dashcode.
Help appreciated,
Ruby
If you're using Dashcode, don't delete the default JS. file. This is important because it has the loaders necessary to render most of the parts in your widget. You can always add your custom javascript file. It also provides code that will allow it to work properly in Dashcode.