Tag Archives: CSS

Bootstrap Shortcoder plugin for WordPress

Bootstrap Shortcoder is a TinyMCE plugin to insert Bootstrap components via a set of shortcodes. Forked from Bootstrap 3 Shortcodes by Michael W. Delaney and Simon Yeldon, under MIT license. Original is unmaintained for 3 years, as it always happens with large projects that do not generate money. As it’s my daily driver, reviving it is the least I can do!

 

Continue reading Bootstrap Shortcoder plugin for WordPress

Best Syntax Highlighter for WordPress 2024: EnlighterJS

EnlighterJS is by far, the BEST syntax highlighter for WordPress. Open source, written in pure javascript, Git available, developers reply to request, great community. Using it can be as simple as adding a single script and style to your website, choosing the elements you wish to highlight, and EnlighterJS takes care of the rest.

Continue reading Best Syntax Highlighter for WordPress 2024: EnlighterJS

Automatic Header Anchors for WordPress Without Plugin

Header Anchors for WordPress with only 3 lines of JS and No plugin?? Yes It’s so easy to set up… Thank you IT Cooking! The JS requires your headers to have an ID, and what better then a Table Of Content plugin to have them for free!

Header Anchors for WordPress Step by Step Process

Requisites

Required: A Snippet loader: we recommend Simple Custom CSS & JS

Simple Custom CSS and JS banner

Optional: A table of content plugin: we recommend TOP Table Of Contents

banner top toc

The JS snippet provided also adds ids to your headers…

Add this JS Snippet to Attach an Anchor to Headers

window.addEventListener("load", function(){
  // Loop through all your headers inside article section only
  // Headers shall be there thanks to TOC plugin, if not we just add them
  // AddOnly h2 and h3, add the headers you want
  $("article").find("h2, h3").each(function() {
    if (!this.id) {
      let id = this.textContent.replace(/[^a-zA-Z0-9]+/g, "-").toLowerCase();
      this.setAttribute('id', id);
    }
    $(this).append('<a class="anchor" href="#'+this.id+'"></a>');  // anchors after
    //$(this).prepend('<a class="anchor" href="#'+this.id+'"></a>'); // anchors before
    });
});

The JS appends/prepends a link with class .anchor to every h2/h3 found on the page, that have an id or not. Will add ids if missing. It does NOT add links to headers outside the article content (read more, etc).

Add this CSS to Format the Anchors

.anchor {
  visibility: hidden;
  text-decoration: none !important;
}
/* add more levels if you need */
h3:hover > .anchor, 
h2:hover > .anchor {
  visibility: visible;
}
.anchor::before { 
  content: "🔗";
}

Anchor is visible on hover, right side, and is an emoji. You can replace the emoji by an <i> from fontawesome if you like.

Result:

css js snippets to add anchor to headers

 

WordPress: Fade Out Excerpt Behind Read More Link

How about an awesome Fade Out effect to “Read more…” link for your post feed? Search no more! Just one CSS hack and done! Themes just neglect this “Continue reading” link and leave it as is. Stuck on the left, no margin, no effects, barely noticeable, plain boring. This easy fade-out effect

Continue reading WordPress: Fade Out Excerpt Behind Read More Link

Twitter Bootstrap Callout CSS Styles 3.x-4.x

 

Bootstrap Callout

The Bootstrap Callout styles in their documentation is really a nice way to draw attention to important information. For some reason these Callouts are not included in the actual Bootstrap distribution.

Here is my interpretation of the missing CSS code for generic Bootstrap Callouts. The color codes for the info, warning, and danger Callouts are a direct pull from their live CSS for the docs, so I added styles for default, success, and primary.

They include a nice background, color derived from Bootstrap color rules. They also include a transparent and a disabled class.

Continue reading Twitter Bootstrap Callout CSS Styles 3.x-4.x

No, You Cannot Add Class to Post Thumbnail

Let me say it again and again until everyone reminds it: NO, You Cannot Add Classes to WordPress Post Thumbnail / Featured Image.

A common idea circulating the web states that you can, and everyone goes with their own snippet of PHP code to add in your Theme index.php. They are all the same, and they are all wrong:

if ( has_post_thumbnail() ) {      // check if the post has a Post Thumbnail assigned to it.
  the_post_thumbnail( 'full', array( 'class'  => 'class2Add' ) );  // Add a class to the featured image/main post thumbnail
}

Why is this wrong? Because the array of class(es) that you pass to the function the_post_thumbnail() replaces the size classes WordPress has generated for this thumbnail.

Continue reading No, You Cannot Add Class to Post Thumbnail

Copy Text Button in WordPress – Click… It’s Copied!

Copy Text Copy Text Copy Text

Adding the ability to Copy Text Code Blocks Without Flash, with a click from a Copy Text Button inside a Syntax highlighted Code Block, that’s real magic. Bonus: the copied code includes Rich Text Format (RTF syntax). This solution relies on Clibboard.JS, and is the easiest one to add to your site. I could make it work under two hours, so I hope this tutorial will help you make it in less!

This text will be copied onto the clipboard 
when you click the button below. 
Try it!

Continue reading Copy Text Button in WordPress – Click… It’s Copied!

Syntax Highlight Code with EnlighterJS for WordPress

Highlight Code with EnlighterJS for WordPress is pretty easy and the results are awesome. There are plenty of highlighter frameworks around for WordPress, such as Crayon.js and Highlighter.js, but I prefer this one.

It’s faster and lighter than Crayon while offering most of its options. Also I like the WordPress plugin integration better.

EnlighterJS For WordPress

This is even easier! Just install EnlighterJS plugin.

hen make sure to activate it and select the CDN for the MooTools framework (if you use CDNjs):

Redources & CDN settings

 

Code added with the add code button will look like this in your posts:

<pre class="EnlighterJSRAW" data-enlighter-language="html">&lt;!--load EnlighterJS:--&gt;

...some js code..

</pre>

EnlighterJS in 2024 now includes a Copy code button. The ‘Copy to Clipboard‘ button I added back in 2017 was a hack done with Clipboard.js, you can check how to add the copy code button for WordPress here.

EnlighterJS For Standalone Sites

First you need to download the package. EnlighterJS css and JS are note currently available on cdnjs for some reason.

Then all you have to do is add this code in the footer:

<!--load EnlighterJS:-->
<link rel='stylesheet' href='css/EnlighterJS.min.css' type='text/css' />
<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/mootools/1.6.0/mootools-core.min.js'></script>
<script type='text/javascript' src='js/EnlighterJS.min.js?ver=3.5'></script>

<pre data-enlighter-language="js">
Element.implement({
...some js code..
});
</pre>

Pretty straightforward isn’t it?

EDIT 2024: EnlighterJS is still the best Syntax Highlighter plugin for WordPress in 2024!