Tag Info

New answers tagged

1

You have a basic mistake in your code. The following code if ( !is_page('my-page') ) { means that if you are not on that page, deregister the scripts. Have a look at the php operators ! -> Not !$x True if $x is not true Also, why not exclude this specific page when you initially enqueue these scripts, something like add_action( ...


1

I'd probably try only enqueueing those scripts on specific pages, rather than enqueuing and then dequeuing them: function wpse158453_enqueue_scripts() { if(!is_page('my-page')) { wp_enqueue_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js' ); wp_enqueue_script( 'jquery-ui', ...


0

Fixed: I have do it the right way, all the time. Now i found, that jquery was deregistered at the themes header.php file. I have deleted it and it works now.


4

Note that if any script in the header at all needs jQuery then it will bump it to header, regardless if it's changed to be enqueued for footer. So while changing it to be queued for footer makes sense it rarely works out when a lot of script stuff is going on.


-1

<?php function your_function() { echo '<p>This is inserted at the bottom</p>'; } add_action('wp_footer', 'my_function'); ?> You can use this hook. This is used to load the script in the footer try it let me know for any doubts.


1

Here is the problem If you try to register or enqueue an already registered handle with different parameters, the new parameters will be ignored. Instead, use wp_deregister_script() and register the script again with the new parameters. You will have to deregister jquery first, the register it again, but becareful because the empty string isn't ...


6

Here's an example of the data returned from the wp_get_update_data() function: Array ( [counts] => Array ( [plugins] => 3 [themes] => 2 [wordpress] => 0 [translations] => 0 [total] => 5 ) [title] => 3 Plugin Updates, 2 Theme Updates ) So the number of ...


5

wp_get_update_data() returns an array in this format counts plugins themes wordpress translations total title So, if you want total count, you need to use it like this $updates = wp_get_update_data(); echo $updates['counts']['total'];


0

Here is a post I have recently done on stackoverflow. It is a modified version of the code you are using. I had the same problem with that code. This is the code that I use to display post views in my website. Please note, admin views aren't counted, and if someone goes to the same post within 12 hours, the second view aren't counted. A second view count ...


0

Re-name your CPT archive to home.php Then use pre_get_posts to alter the home page query so only CPT's display function wpsites_home_page_cpt_filter($query) { if ( !is_admin() && $query->is_main_query() && is_home() ) { $query->set('post_type', array( 'your-cpt' ) ); } } ...


1

get_userdata() returns you the data of a specific user (by id), while get_currentuserinfo() returns data about the current logged in user. For example, you could use get_currentuserinfo() to welcome a user (e.g. "Welcome back John"), if he's signed in.


0

I am using this code, i Hope it helps you. function defer_parsing_of_js ( $url ) { if ( FALSE === strpos( $url, '.js' ) ) return $url; if ( strpos( $url, 'jquery.min.js' ) ) return $url; return "$url' defer='defer"; } add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );


0

It display NULL, because it doesn't exist. If you want to use global variables in another function than where you defined it, you have to re-declare that as global again. If you omit global keyword, it will be defined in that function scope, not in global scope. In your functions.php use global keyword add_action('pre_get_posts', 'page_sr2_pgp'); ...


0

As indicated in the comments, you should return the string, not echo it: add_shortcode('yt', 'getYoutubeDetails'); function getYoutubeDetails($atts) { extract(shortcode_atts(array( 'video' => '' ), $atts)); // Get YouTube data via the API $JSON = file_get_contents("https://gdata.youtube.com/feeds/api/videos?q=$video&alt=json"); ...


0

The is_login_page() function is taken from here function is_login_page() { return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')); } function my_redirect() { //if you have the page id of landing. I would tell you to use if( is_page('page id here') instead //Don't redirect if user is logged in or user is trying to sign ...


1

This should work for the rel attribute: /** * Create a rel attribute from the image categories * * @see http://wordpress.stackexchange.com/a/158024/26350 */ add_filter( 'get_image_tag', function( $html, $id ) { $rel = array(); foreach( (array) get_the_category( $id ) as $cat ) { $rel[] = $cat->slug; ...


0

Your functions have nothing to do with each other. Is all you want a button that when clicked adds [tooltips class="top_tooltip" title="Your Tooltip here"] Text here [/tooltip] to the editor? -- This is currently what your doing -- First Function: function tooltip( $button ) is adding your tooltip shortcode Second Function: mce_tooltip( $button ) is ...


0

Here's a short alternative way (untested) to the other great answers: add_action( 'init', 'custom_feeds' ); function custom_feeds() { foreach( array( 'feedname1', 'feedname2' ) as $name ) { add_feed( $name, function() use ( $name ) { get_template_part( 'rss', $name ); } ); } ...


1

You could move the logic into a class that remembers the names and the template parts. Example, not tested: class Custom_Feeds { private $feeds = array (); /** * @param array $feeds */ public function __construct( Array $feeds ) { $this->feeds = $feeds; } /** * @wp-hook wp_loaded * @return void */ ...


1

Here's what I do to keep my RSS Templates together though depending on your version of PHP this may not work but it's pretty clean. You can add multiple feeds here. /** Register Our RSS Feeds **/ function my_rss_templates() { add_feed( 'feedname2', function(){ get_template_part('rss', 'feedname2''); }); // Rinse and Repeat... } ...


0

I would not recommend hard-coding them into either the header.php template file or functions.php. The reason is that they are then tied into your theme, and if you switch themes you will lose them. Option 3 I tend to stay away from, because the third-party plugins tend to bring along a lot of extra bloat. My advice would be to go with option 2, as it is ...


0

Hook into wp_head in your functions.php file. add_action('wp_head', 'add_your_stuff'); function add_your_stuff() { ?> <link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri();?>/favicon.ico" type="image/x-icon" /> <link rel="apple-touch-icon" href="<?php echo ...


1

First, you are confused. It is not the same "override a function" that remove a filter. Assuming that you want to remove a filter, I think that your code should be: function remove_html5_insert_image(){ remove_filter('image_send_to_editor','html5_insert_image', 10); } add_action('after_setup_theme','remove_html5_insert_image'); Note that the filter ...


0

The global $wp object contains the current request, which can be used to get the current URL anywhere on the site. A helper function like the following demonstrates how this works: function wp157715_current_url() { global $wp; $current_url = trailingslashit( home_url( $wp->request ) ); return $current_url; }


0

you can use bloginfo('url') but also can use get_option function, check documentation: http://codex.wordpress.org/Function_Reference/get_option and by the way we cannot access your localhost :)


0

As posed in question the way to retrieve the current URL to the root of the site would be home_url() for site's front-end. However there are multiple functions that deal with URLs to specific kinds of pages. It's not clear what you are linking to (post? page? archive?), but there are likely specific URL-forming function for it which should be used over ...


1

bloginfo('url') should get you the URL for the installation. EDIT: I guess you could also use get_permalink()


0

To show your custom excerpt more text when a post has a manual excerpt, you can filter the excerpt using the get_the_excerpt filter, use has_excerpt() (http://codex.wordpress.org/Function_Reference/has_excerpt) to determine whether the post has a manual excerpt or not, and append the output of your already-existing custom excerpt more function to the excerpt ...


0

By Javascript you can pop-up the media and on select you can update the image URL to the textbox. Below is the code. var custom_uploader; jQuery('<Should-be-a-button-selector>').click(function(e) { e.preventDefault(); //If the uploader object has already been created, reopen the dialog if (custom_uploader) { custom_uploader.open(); ...


1

You don't need to create additional functions, just re-use what you already have and tweak it a bit: function theme_add_bootstrap() { wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/third_party/bootstrap/css/bootstrap.min.css' ); wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . ...


1

For historical bloggy reasons, the_date in WordPress won't show the same date twice in a row. This is for grouping purposes. The fix is easy: Use the_time instead. It behaves exactly the same as the_date, but without the internal historical logic. Also no need to rewrite any complicated code, just change three characters. :) Note: the_time is missing the ...


1

As it says right there is its inline documentation — the function is meant to only output the result "once per date". In typical chronological loop of posts it will "collapse" for posts made on same day. In less typical loop it might lead to pretty bizarre outputs. If you dig far and deep enough in version control history you might be able to dig up ...


0

wp_get_archives() can not display post date, but you can force wp_get_archives to display date by using hook. Put the following function at the end of your custom template file or functions.php file - function wpse_the_title($title, $id){ if( $date = get_the_date('d/m/Y', $id) ){ $title = sprintf('%s - %s', $date, $title); } return ...


1

You simply need to run your code on a higher priority than what the parent theme is, the default on add_action function is 10 so you can use: function s157343_unregister_widgets() { unregister_widget( 'Chocolat_Widget_New_Entrys' ); } add_action( 'widgets_init', 's157343_unregister_widgets', 20 ); This will unregister that widget. Of course, you can ...


1

1.0.0? Really?! Anyway you could try the print_scripts_array filter: // Hack of wp_prototype_before_jquery() in "wp-includes/script-loader.php" function wpse157295_print_scripts_array( $js_array ) { if ( false === $jquery = array_search( 'jquery-core', $js_array, true ) ) // Now 'jquery-core', not 'jquery' return $js_array; $keys = array( ...


0

Here is what I ended up with: Basically, I had the logic of the timing at the bottom wrong. Figuring out times and dates and what note is hard... add_action('init', 'delete_unclaimed_apps'); function delete_unclaimed_apps() { $availapps = get_posts(array( 'post_type' => 'appointment', 'post_status' => 'publish', ...


0

Here's one way to add post tags after the content on single posts only using the_content filter in a custom function from your functions file. Uses the_tags function tags_after_single_post_content($content) { if( is_singular('post') && is_main_query() ) { $tags = the_tags('<div class="entry-meta">Tagged with: ',' • ','</div><br ...


-1

Displays a list of tags with links to each one and a specific class for each tag: $tags = get_tags(); $html = '<div class="post_tags">'; foreach ( $tags as $tag ) { $tag_link = get_tag_link( $tag->term_id ); $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>"; $html .= ...


1

It seems the problem was it wasn't recognizing it was a page in the first place and thus couldn't recognize if there was a template applied to it. Changed if (is_page_template('page-templates/page-nosidebar.php')) { to if (is_page() && !is_page_template('page-templates/page-nosidebar.php')) {


0

'echo' statement will not work in shortcode function. shortcode function is just returning the variable; So your code will be like this: if(get_field('group')) { $html = ''; $html.= "<ul class='sponsors'><h2>" , get_the_title() , "</h2>"; while(has_sub_field('group')) { $attachment_id = get_sub_field('image'); ...


0

if( in_array( 'comments',$meta_info ) ){ $key="link"; echo '<span class="post-meta-info with-cmt">' . apply_filters('yt_icon_comment', '<i class="fa fa-comments"></i>') . ' '; comments_popup_link( __( '0 Comments', 'theme' ), __( '1 Comment', 'theme' ), __( '% Comments', 'theme' )); echo ...


0

Well, here's what I found. It doesn't quite explain why the editor was breaking, but it does explain how to add a button properly, without breaking the editor. The PHP code I was trying to add to functions.php actually needed to be added as a plugin. Combining directions from this StackExchange post and this tutorial, I created a WordPress plugin containing ...


2

You did not returning the default class if you are not viewing the contact page. Try this code once if(! function_exists( 'remove_hentry' )) { function remove_hentry( $classes ) { $classes[] = customTheme_layout_class(); if( is_page('contact') ) { $classes = array_diff( $classes, array( "hentry" ) ); } ...


0

There are a few problems with your code which I will take you through. PROBLEM 1 Whether you are using wp_enqueue_style() wp_enqueue_script() wp_register_style() wp_register_script(), they all have the first parameter in common, $handle. This is $handle (string) (required) Name of the stylesheet (which should be unique as it is used to ...


1

This could be the matter of adjusting the priority of your filter callback, since the plugins files are executed before the functions.php theme file. That could explain why it works in your functions.php file, if the priority is the same. When you add the code snippet to a plugin, it might be executed before the other plugins that use the same filter. The ...


1

pre_get_posts and WP_Query uses the exact same parameters, so if you need to know which parameters you can use with pre_get_posts, simply visit the WP_Query page in the codex. There is another trick which you can use to get all the parameters (query_vars) you can use. Just add this on the page that you need to get the query_vars from, refresh the page, and ...


0

Please check the category parameters in the WP_Query documentation.


5

When using Ajax API, and you want to make the ajax callback available for non-logged users, you need to add 2 actions, "wp_ajax_{$action}" and "wp_ajax_nopriv_{$action}". Using only the first action, the callback will be called only for logged users, using only the second it will be called only for non-logged visitors. Try this: function check_username() ...


3

This should hopefully do the trick: /** * Append the image categories to the current image class. * * @see http://wordpress.stackexchange.com/a/156576/26350 */ add_filter( 'get_image_tag_class', function( $class, $id, $align, $size ) { foreach( (array) get_the_category( $id ) as $cat ) { $class .= ' category-' . ...


0

You need to include wp-includes/user.php file when you are using ajax for user related functions. function check_username() { require_once (ABSPATH.'/wp-includes/user.php'); $username = $_POST['user']; if ( username_exists( $username ) ) { $return['user_exists'] = true; } else { $return['user_exists'] = false; } echo ...



Top 50 recent answers are included