Adding javascript to functions.php causes problems with my template

jQuery is already loaded with WordPress, so you won’t need <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js”></script> When using jQuery with WordPress, you’ll likely require no-conflict wrappers : https://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers There are likely JS errors being outputted in your browser console, so giving us more info on errors can prove useful as well. There is definitely a better way – starting … Read more

WordPress function only executes once

It will be bit tricky to detect if user just get into site. But generally there will be no referer, hence wp_get_referer() will return false. My code check if there is referer, if no then they get redirected to post page. NOTE: When user access a page in admin by typying url in adressbar then … Read more

Change Slug of a Custom Post Type

In the code you posted, the filter ctc_post_type_item_args gets applied to the $args array before it is passed into register_post_type(). Putting a function into your themes functions.php and hooking it to the filter should do the trick: function wpse_191003_ctc_post_type_item_args( $args ) { $args[‘rewrite’][‘slug’] = “your_new_slug”; return $args; } add_filter( ‘ctc_post_type_item_args’, ‘wpse_191003_ctc_post_type_item_args’ );

esc_url( ) won’t use https

esc_url never force the URL to protocol it’s only checking and escaping the passed URL from invalid characters, the $protocols variable is an array of acceptable (white list) protocols not for forcing destination URL. // Forcing URL to https instead of http $YOUR_URL = esc_url($YOUR_URL); if( ‘http’ == parse_url($YOUR_URL, PHP_URL_SCHEME) ){ $NEW_URL = str_replace(‘http://’, ‘https://’, … Read more

Visual Composer creating own shortcodes with vc_map() to return simple Image

Visual Composer adds the image ID to the generated shortcode. This gives you more flexibility with image sizes. You can use it like this: $imageSrc = wp_get_attachment_image_src($image_url, ‘thumbnail’); if( $imageSrc ) { echo ‘<img src=”‘ . $imageSrc[0] . ‘” />’; } The thumbnail param could be replaced by medium or another valid image size. The … Read more

Disable wp_is_mobile()

wp_is_mobile() does not have any filters or ways to override. What you’ll need to do is build a wrapper of your own around wp_is_mobile() and use that in your code where you’ve used wp_is_mobile(). Something like the following prototype could work for you. Ultimately a better option over the URL parameter might be to use … Read more

Scripts not loading when using the wp_enqueue_scripts action

get_stylesheet_uri() loads the main stylesheet of the theme. If you need to load additional stylesheets, you need to use get_template_directory_uri() for parent themes and get_stylesheet_directory_uri() for child themes. If you have stylesheet called custom.css in the root in a child theme, you will use get_stylesheet_directory_uri()’ . /custom.css’ You should also make sure that you have … Read more

how to use pre_gets_posts to exclude one queried ID from homepage loop

Couple of issues here You custom query should be inside your conditional statement Use get_posts which only returns the $posts property wp_reset_query() is used with query_posts which you must never ever use No need to the $post global Your code should look something like this add_action( ‘pre_get_posts’, ‘cdbz_modify_main_query’ ); function cdbz_modify_main_query( $query ) { if … Read more