Entirely Different Functions.php per Page?

functions.php will load automatically for every page load, but you could certainly move most of the content of your current functions.php to other files and use functions.php itself as a primarily a kind of switch. Caveat: You may have to hook some of your switching functions to get access to certain data. For example, functions.php … Read more

the_widget() inside functions.php

The function the_widget() does not return any output it only echos it. If you want to save its output to a variable you need to use output buffering. ob_start(); the_widget(‘My_Custom_Widget’); $w = ob_get_contents(); ob_end_clean();

Linking Javascript in functions.php file

So this looks like you’re using a JS package manager, possibly Dustin Diaz’s ScriptJS? And I’m assuming you are storing all these files within your theme folder it would then be just a matter of linking to your script.min.js file via the wp_enqueue_script mechanism as follows: function wpse143251_enqueue_theme_scripts() { wp_enqueue_script( ‘dustindiaz-scriptjs’, get_template_directory_uri() . ‘/assets/components/plugins/ajaxify/script.min.js?v=v1.9.6&sv=v0.0.1’ ); … Read more

How to safely edit functions.php

I don’t really think there is a safe way to make changes to your functions file, and for that matter any other template file. And I personally think that the back end editor are a big evil. It is unwise to make any changes to a live site, period. Any type of syntax or fatal … Read more

Changing the header image using WPML

You can use site_url() or get_site_url(). Depending on your install and setup, you could as well use network_site_url() – which is what I would prefer as it falls back to site_url() internally if it is no multisite setup. The site_url( $path, $scheme ); function also takes two arguments: The $path can be used to append … Read more

How to print the current post depth as update notification?

You should wrap your condition inside the function, rather than the function inside the condition (this will also prevent errors with code running too early as WordPress loads). function my_admin_notice() { global $wpdb, $post; $depth = $wpdb->get_var( $wpdb->prepare( “SELECT post_parent FROM $wpdb->posts WHERE ID = %d”, $post->ID ) ); if ( $depth == ‘0’ ) … Read more

Optimize CPT-function with a loop

Finally I got the solution. One of the major problems was the usage of “get_post_custom” for fetching the database. I used “get_post_meta” instead and it was a lot easier to work with the array that was created by that function. I am sure that it would have been possible to do it with the first … Read more

Displaying Event within two given time frames

Querying on the meta data table is slow, and as since it’s also used for general data, you need to be careful about your date format if you’re storing dates there. For instance, with dmY format: 01112014 ( 1st November 2014 ) 11012014 ( 11th January 2014 ) 12052014 ( 12th May 2014 ) is … Read more

contact form in template with jquery,validate and ajax

WordPress is running Jquery in noconflict mode. (WordPress Codex Reference) or read this brief article I posted some time ago. View it here. You need to replace: $(document).ready(function(){ With this: jQuery(document).ready(function($){ So all together, try this: jQuery(document).ready(function($){ $(“#contact_form”).validate({ rules: { name: “required”, email: { required: true, email: true }, message: “required” }, messages: { name: … Read more