Is it possible to add blogger's conditional tags into jquery code? For example how can I do something like this...
if(cond='data:blog.pageType == "item"'){...}
Yes.
document.addEventListener("DOMContentLoaded", function() {
if (typeof _WidgetManager !== "undefined") {
var data = _WidgetManager._GetAllData();
if (data.blog.pageType == "item") {
alert('item');
}
if (data.view.isHomepage) {
alert('homepage');
}
}
}, false);
As long as the code is present in the Blogger theme (Theme > Edit HTML), you can use the b:if
conditional statements directly inside the <script>
tags. Like for example -
<script>
<b:if cond='data:blog.pageType == "item"'>
<!-- Do Something specific to the post page-->
</b:if>
</script>
Note: Don't add the CDATA section to the <script>
otherwise <b:if>
conditions will stop working inside the <script>
tag
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With