wp_enqueue_script & constants?
The value you pass to wp_enqueue_script should be the URL of the script, not the local file path. wp_enqueue_script(‘my-script’, get_template_directory_uri() . ‘/my-scripts/my-script.js’);
The value you pass to wp_enqueue_script should be the URL of the script, not the local file path. wp_enqueue_script(‘my-script’, get_template_directory_uri() . ‘/my-scripts/my-script.js’);
You can use the first one, as long as the scripts have been registered, it will enqueue the dependencies prior if they haven’t already. JQuery etc should already have been registered so version A is perfectly fine
You’re registering/enqueueing your script wrong. You should register/enqueue in your theme’s functions.php file instead of inside the header/page. Also, you need to use your theme’s directory … which will be along the lines of mydomain.com/wp-content/themes/BLANK-Theme/js/SliderViewer-1.2.js. Use this code in functions.php: function my_scripts_enqueue_method() { wp_enqueue_script( ‘SliderViewer’, get_template_directory_uri() . ‘/js/SliderViewer-1.2.js’ ); } add_action( ‘wp_enqueue_scripts’, ‘my_scripts_enqueue_method’ ); This … Read more
I’m at work at the moment (sorry boss), so I can’t test this, but the snippet below should be the proper way of testing if the ‘featured_post’ post type exists, and then enqueue the script if it has any posts. if ( is_front_page() && post_type_exists(‘featured_post’) ) { // We are at the front page, and … Read more
I would wrap the whole thing in a class and put your data into a class var. class WPA69616_Plugin { private $data=””; public function __construct() { add_shortcode(‘my_shortcode’, array($this, ‘add_content’)); add_action(‘wp_footer’, array($this, ‘output_content’)); } public function add_content($atts) { extract( shortcode_atts( array( ‘content’ => ” ), $atts ) ); $this->data .= $content; } public function output_content() { … Read more
Use wp_localize_script to pass data from php to your javascript: wp_register_script( ‘wpa_script’, get_template_directory_uri() . ‘/js/script.js’, array(‘jquery’), null, false ); wp_localize_script( ‘wpa_script’, ‘WPAData’, array( ‘slides’ => array( ‘http://google.com’, ‘http://google.co.uk’ ) ) );
Because calc_script is inside your class, it’s not publicly available like a regular function. So, change your enqueue call to this: add_action( ‘wp_enqueue_scripts’, array( $this , ‘calc_script’ ) ); And make calc_script() public. Edit: Your add_action() is in the class as well, it needs to be in another function, preferably one hooked to the init … Read more
While you can practically control order of hooked things by priority, it’s not always the right tool for the job. In case of styles you should be using appropriate wp_enqueue_style() function which allows you to easily set up elaborate dependencies which will be automagically processed by WP to produce desired order of styles output. Unfortunately … Read more
I think you’re using the wrong approach. Rather than removing the submenu item, alter how the post type was registered, and change the show_in_menu argument. Hook into init way late and change the argument. <?php add_action(‘init’, ‘wpse99123_post_type_switcher’, 999); function wpse99123_post_type_switcher() { global $wp_post_types; $wp_post_types[‘contact’]->show_in_menu = true; // put it back in the menu } Then, … Read more
get_stylesheet_uri will return the current theme’s stylesheet– the child stylesheet if it is a child theme. While not entirely clear from the Codex entry for that function, it is clear from the entry for get_stylesheet_directory_uri, which is used by get_stylesheet_uri. What should be happening is that the child stylesheet is being enqueued twice under different … Read more