using jQuery on only one page

You don’t need to add it on a template, you can use the wp_add_inline_script() function. It’d be something like: function tabs_enqueue() { if(is_page( 205 )) { wp_enqueue_script( ‘ui’, get_template_directory_uri() . ‘/js/ui/jquery-ui.min.js’, [], ‘1.8’, true); wp_add_inline_script( ‘ui’, ‘jQuery(window).load(function() { //code here });’ ); } } add_action(‘wp_enqueue_scripts’, ‘tabs_enqueue’); Hope it helps!

Why does re-using this function not work? [closed]

Function “works” once because before first call of is_service_class(), function is_personal not exists and whole this block is executed if ( ! function_exists( ‘is_personal’ ) ) { // declaration and use of function } In next call of is_service_class() is_personal is declared and the entire block is skipped. Inside the condition if ( !function_exists( ‘is_personal’ … Read more

ACF not showing

the_field() function shows the value and it doesn’t get/return anything. Like the_title() and other template tags starting with the_. It means that: This line prints the value and $hero variable is empty. $hero = the_field(‘hero_title’); This line prints only <h1> tags. echo ‘<h1>’.$hero.'</h1>’; What you want is: echo ‘<h1>’ . get_field(‘hero_title’) . ‘</h1>’;

enqueue_script with filemtime javascript not working

wp_register_script() function is accepting the 5 parameters. You are passing the 6 parameter. So replace the wp_register_script( ‘lib’, get_template_directory_uri().’/js/lib.js’, array(), filemtime(get_template_directory() . ‘/js/lib.js’), null, ‘all’ ); WITH wp_register_script( ‘lib’, get_template_directory_uri().’/js/lib.js’, array(), filemtime(get_template_directory() . ‘/js/lib.js’), true );

How to use selected WordPress functions?

You may be able to have WordPress push data to the session or to your custom PHP, rather than trying to load WordPress each time you need to query some the user. I’m not sure what other functions you want to call. The alternative is to use the WordPress REST API, take a look at … Read more

allow only one post in specific category

After the post save (using save_post hook) you check if the saved post has your “unique” category, and if so remove the category from the other posts, keeping the one you just saved. add_action( ‘save_post’, ‘set_post_unique_category’, 10,3 ); function set_post_unique_category( $post_id, $savedPost, $update ) { // Only set for post_type = post if ( ‘post’ … Read more

file_get_contents – failed to open stream

I agree that this is PHP rather than WP question. To bring it closer to WP I do suggest to take a look at following functionality: HTTP API is highly suggested for making HTTP requests; add_post_meta() and related meta functions to store post-specific information; the_shortlink() function, that is suggested template tag to use for natvie … Read more

shortcode help require

Here you go: add_shortcode(‘latest_tweets’, ‘latest_tweets’); function latest_tweets($atts){ extract(shortcode_atts(array( ‘max’ => 5 ), $atts)); $twitter_id = esc_attr(strip_tags($atts[0])); // try to get data from cache to avoid slow page loading or twitter blocking if (false === ($output = get_transient(“latest_tweets_{$twitter_id}”))): $doc = new DOMDocument(); $feed = “http://twitter.com/statuses/user_timeline/{$twitter_id}.rss”; $doc->load($feed); $output = “<ul>”; $i = 1; foreach ($doc->getElementsByTagName(‘item’) as $node) … Read more