Why load JS through the CMS framework? [duplicate]

The primary reason we use enqueue scrips is because WordPress will properly manage all the requests. For example, if two different plugins are using a certain third party library, WordPress will make sure that the script is only loaded once. It will also do a good job of handeling multiple version of the same script. … Read more

Display a div when post has a certain tag

You could use a simple conditional and check if the post has a term using has_term(): has_term( $term, $taxonomy, $post ); Pass in your Term Slug, the taxonomy ( which sounds like you’re using post_tag and the post object, no javascript needed. <?php if( has_term( ‘term_slug’, ‘post_tag’, $post ) : ?> <div> Show your div … Read more

Delay JavaScript files from loading

I think you should use setTimeout to pause the execution of the script without blocking the UI. setTimeout(function(){ //your code to be executed after 2 seconds }, 2000); So your code will become. setTimeout(function(){ document.addEventListener(“DOMContentLoaded”, function(event) { document.getElementsByTagName(“body”)[0].setAttribute(“ng-app”, “app”); }); }, 2000); This will delay script execution for 2 seconds. You can change this value … Read more

How to correctly add Javascript to this PHP ‘Page Not Found’ Page?

Problem The Short Version The problem isn’t how you’re using those scripts or where you’re placing them – it’s how the authors of those scripts wrote them. The Long Version Your “superfish” script which controls the functionality of your navigation menu is throwing errors because $.browser is undefined. While $.browser was deprecated more than 3 … Read more

Only show a Post once in 10 visits

function lsmwp_post_limter($ids, $in, $count) { $i = rand(1,$count); if ($i <= $in) { return($ids); } else return false; } function lsmWpfilter($posts){ $result = []; foreach($posts as $post){ $res = lsmwp_post_limter($post[‘postId’], $post[‘in’], $post[‘count’]); if ($res){ $result[] = $res; } } print_r($result); return $result; } $exluded_posts = array( array(‘postId’ => 28741 , ‘in’ => 2, ‘count’ => … Read more

Scripts not loading through function Method in WordPress Theme

There are several fundamental problems with what you’re trying to do that prevent you reaching your goal The Problems Naming You register 2 scripts, but you name them both ‘custom’. How is WordPress supposed to know which script you meant when you later tell it to display ‘custom’? /* Register scripts. */ wp_register_script( ‘custom’, JS … Read more

disable tags on wordpress text editor

WordPress already disallows the use of JavaScript in the editor for users without the unfiltered_html capability. By default, only the Administrator and Editor roles have this capability. If necessary, you could remove this capability from Editor users as well. (It doesn’t make sense to remove it from Administrators, because they will still have the ability … Read more