Is it safe to include a javascript file in a template’s php file?

As @N00b mentioned Yes, it is safe adding a JS script as long as it doesn’t include any sensitive information. JS is fully exposed to client, you shouldn’t do it anyway. But your situtaion it is better to create a site specific custom plugin and add JS using it. Example : function themeslug_enqueue_style() { wp_enqueue_style( … Read more

Get page id of current page from template [duplicate]

To get the ID of the page being queried from outside the loop or before the global post object has been set, use get_queried_object_id(). <?php /** * Template Name: Contact Page */ get_header(); ?> <?php $page_id = get_queried_object_id(); echo get_post_meta( $page_id, ‘contact_page’, true); ?> <?php get_footer() ?>

Custom page for WooCommerce’s /product-category/

product-category URL uses taxonomy-product-cat.php which calls archive-product.php you will need to override it by creating the same file with the same name in themefolder/woocommerce/archive-product.php You can open any file in templates folder in the WooCommerce plugin and you will find a line in the very top comment describes how to override the file. Don’t forget … Read more

Query from a different database than the default

I don’t know why the mysql_connect isn’t working inside WordPress. But an easier way of doing it would be to use the $wpdb class. Try replacing your code with this: $second_db = new $wpdb( ‘user’, ‘pass’, ‘dbname’, ‘host’ ); $q = $second_db->get_results( ‘SELECT * FROM vars’ ); var_dump( $q ); and see if you get … Read more