BootstrapCDN – WordPress CDN Plugin

I want to use some of the responsive features of Bootstrap and Fontawesome on my sites but have a personal preference of not wanting to pollute my header.php files with code so decided to look for a plugin and found BootstrapCDN which will give me a simple way of updating/enabling/disabling both Boostrap and Fontawesome.

I had found a decent Bootstrap CDN plugin on the main WordPress website but it was a bit outdated so in looking at the authors files I found that simply updating the bootstrapcdn.json file with newer data resolved that and made it usable.

I am a bit confused with the authors notes though as it states that in a 0.0.3 update he renamed netdna to maxcdn, which is not the case when I looked at the JSON file. Perhaps he meant elsewhere in his code.

For alternatives to using a plugin, Prakhar over at 3nions has a cool article titled How to add Bootstrap to WordPress: Use these 3 Best Methods describing three great alternative methods, one of the primary methods being the use of this plugin.

Links to respective websites, authors WordPress plugin page and modification of the bootstrapcdn.json of the plugin are below.

Bootstrap – Get from BootstrapCDN or Bootstrap.com websites.

Fontawesome – Get from BootstrapCDN or Fontawesome.io websites.

BootstrapCDN – WordPress CDN Plugin – Get from the WordPress website.


{
"timestamp": 0,
"bootstrap": {
"3.3.7": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
},
"3.3.6": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
},
"3.3.5": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"
},
"3.3.4": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"
},
"3.3.2": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"
},
"3.3.1": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"
},
"3.3.0": {
"css": "//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css",
"js": "//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"
},
"3.2.0": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"
},
"3.1.1": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"
},
"3.1.0": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"
},
"3.0.3": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"
},
"3.0.0": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"
},
"3.0.0-noicons": {
"css": "//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.no-icons.min.css",
"js": "//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"
}
},
"fontawesome": {
"4.7.0": "//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css",
"4.2.0": "//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css",
"4.1.0": "//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css",
"4.0.3": "//maxcdn.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css",
"4.0.2": "//maxcdn.bootstrapcdn.com/font-awesome/4.0.2/css/font-awesome.min.css",
"4.0.1": "//maxcdn.bootstrapcdn.com/font-awesome/4.0.1/css/font-awesome.min.css",
"4.0.0": "//maxcdn.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.min.css",
"3.2.1": "//maxcdn.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css"
}
}

Preventing comments on the image attachment pages in WordPress

I think Don’t Tread On Me has pretty much lost its meaning these days, especially with regard to spamming. I really hate spam and wish nothing but wicked things to those who do it. In any event, lately I had started seeing spam type comments cropping up on image attachment pages of my site and in checking them out I had no idea that comments could even be placed on these pages. Perhaps I missed that in reading the WordPress Codex at some point or I just plain forgot.

I’m not sure why WordPress does not have a central settings area specifically for controlling comments but it would be nice. Essentially this is left to configuring by way of manual editing of code or using third party plug-ins and I question the necessity of the latter since it seems like a no-brainer to just add the functionality.

The way WordPress handles comments currently allows someone to click on a thumbnail of an image and that in turn displays the image as a post along with a comment area under it. I guess comments on individual images is valuable in some way?

picturespam_40

In any regard, it really drove me nuts whenever I would get a comment notification, review it and find it was on the image page in Russian, jibberish or just nonsense text so I decided to review some of the php files to look for anything related to comments.

I’m currently using the Misty Lake theme by Automattic and noticed in the Image Attachment Template (the image.php file) that towards the bottom it instantiated a call to comments_templates.

mistylake code_60

After making a backup of the image.php file, backups are always recommended, I used the editor in WordPress to removed the line, updated it, and now the comment area no longer appears on image attachment posts.

I will need to remember this moving forward should I ever update the theme as I am sure at some point the image.php file will be updated and I will need to manually remove the line again. Equally, should I change themes I will need to remember to double-check comments. It has actually been a few weeks since I made this manual modification and I have not experienced the spam as I was before. Hopefully the info will help someone.

Well, as an update to this, I decided to create my own custom-functions.php and add a function to do the above.

function DisableMediaComments( $open, $post_id ) {
$post = get_post( $post_id );
if ( 'attachment' == $post->post_type ) {
$open = false;
}
return $open;
}
add_filter( 'comments_open', 'DisableMediaComments', 10, 2 );

The code above should generically work within any theme. There is also another way, based on the comments_template line I removed from the theme I am using. Change the comments_template line from this:

<?php comments_template(); ?>

To this which will only show a Comments form if the parent post has comments enabled:

<?php if (comments_open($post->post_parent)) {
 comments_template();
} ?>

So with the above, if your post is enabled for comments then so will any attached images. Otherwise, if comments are disabled in the post, they will also be disabled for attached images. I believe I Googled the aforementioned and saw it on a few websites/forums so kudos go to whomever posted it first.

In any regard, I still elected for the function in my custom-functions.php file. To me its just easier that way and I don’t have to worry about any code changes to the theme.