Tag Info

Hot answers tagged

13

The default response from admin-ajax.php is, die( '0' ); ...by adding your own exit() or die() after returning your desired content prevents the default response from admin-ajax.php being returned as well. It also generally means that your ajax call has succeeded. Ultimately, to answer your question, it's meant to work this way. What you are doing by ...


10

Add this snippet to your functions.php function redirect_the_single_post() { if (is_search() && is_main_query()) { global $wp_query; if ($wp_query->post_count == 1 && $wp_query->max_num_pages == 1) { wp_redirect( get_permalink( $wp_query->posts['0']->ID ) ); exit; } } } ...


9

the_permalink echos out the permalink of the current post to the frontend. get_permalink however returns it as a variable, but does not echo it out. You can also pass a post ID to it if you want the permalink of another post. the_permalink is equivalent to: echo get_permalink(); Which is very close to what it actually does. This is the implementation of ...


8

Use the second parameter of edit_post_link(), the before parameter: <?php edit_post_link( 'Edit', 'string of text: ' ); ?>


8

This has always been a bugbear for me - the lack of on-demand image sizing, and the subsequent number of files you can end up with if you have lots of sizes! I can see the logic behind your efforts - the trouble is, add_image_size only truly comes into play at point-of-upload. As such, is_page_template(..) will always be false. A quick google dug up Aqua ...


6

The Reply links I assume your Reply links look like this: <a class="comment-reply-link" href="/2013/12/29/hello-world/?replytocom=32#respond" onclick="return addComment.moveForm('comment-32', '32', 'respond', '1')">Reply</a> and the Cancel Reply link: <a rel="nofollow" id="cancel-comment-reply-link" ...


6

The if function_exists approach allows for a child theme to override the function definition by simply defining the function themselves. Since child theme's functions.php files load first, then they will define the function first and the parent's definition will not get loaded. The other approach of using action or filter hooks works just as well, and child ...


5

The second $item argument, which is being made available to your filter function, contains a menu item object. If dumped it looks something like this: [1] => WP_Post Object ( [ID] => 2220 [post_author] => 1 [post_date] => 2012-12-26 19:29:44 [post_date_gmt] => 2012-12-26 17:29:44 [post_content] ...


5

This answer contains a fairly simple CSS solution. Essentially, you'd add the following to your stylesheet: .cat-item cat-item-7 { list-style-image: url('my-epic-news-icon'); } cat-item cat-item-11 { list-style-image: url('my-epic-jquery-icon'); } etc Yes, it's not a very dynamic solution, but your categories aren't likely to change I ...


5

There is no real difference between the two methods. When using method A, only the hooking is bound to the condition (i.e., the function is defined no matter what), while in method B the definition of the function as well as the hooking is. Another thing is the following method (which you did not include): function my_hooked_function() { if (! ...


5

If this is how it looks: <img class="alignleft size-medium wp-image-8530" alt="..." src="#" width="413" height="275" /> <img class="alignleft size-medium wp-image-8529" alt="..." src="#" width="413" height="275" /> Then you have to put them together like this: <img class="alignleft size-medium wp-image-8530" alt="..." src="#" width="413" ...


4

Here's a much better solution: Don't edit the theme's functions.php file. Don't put your custom code into that file either. If you have snippets of code for a site, put them into a custom plugin. Put each one into its own plugin, in fact. Separate them by functionality. I even made a handy dandy plugin to make this easier, called Pluginception. The nice ...


4

Anywhere in your script, you can define a global variable as follow: Using the superglobal $GLOBALS array. This array is predefined by PHP, and is available in all scopes. It's an associate array, containing all global variables as a key-value pair. ie: the key will be the variable name, and value will be the value of the variable. ...


4

If I understand the problem setup correctly, you could try to do the break and widget class counting within the wp_nav_menu_objects filter. Here's an updated example, it's rather expanded because of the extra debug part: add_filter( 'wp_nav_menu_objects', function( $items, $args ) { // Only apply this for the 'primary' menu: if( ...


4

Yes, you can replace existing icons by overwriting them via CSS. Make sure to check if the existing icon is set via img or background-image and add some CSS to overwrite it with one of the available icons. You can find all available icons and the appropriate selector at the Dashicons Website. To replace the icon of the Yoast SEO Plugin you can add this ...


4

Your problem is here: $welcomePage = get_post( 5 ); echo $welcomePage -> post_content; Shortcodes are processed on display by via a filter on the_content which is called by the function the_content(). You've bypassed that functionality and are echoing the raw post data. You need to output your code using a proper Loop or explicitly process the ...


4

The internal implementation details of that feature are of questionable sanity. If you take a look at said featured-content.php template you would see that it get posts from twentyfourteen_get_featured_posts() however the only thing that function has is twentyfourteen_get_featured_posts filter from quick look at which in peculiar fashion nothing is ...


4

What you are looking for is a "MU-Plugin"-- "Must-Use Plugin".. Originally these were called "Multi-User Plugins" and were intended for exactly your purpose-- to provide a way for site admins to enable functionality on all sites of an installation. Create a directory at /wp-content/mu-plugins/ and put your PHP file(s) in it. WordPress will load the files ...


4

Assumptions: You don't explain how you want to install the Font Awesome package, so I just assume for the moment that you use the plugin Font Awesome Icons. You wrote: Before anyone says use a background image, I do not want to do that. I would like it to be physical. so I assume you want to use the <i> tag directly, for example: <i ...


4

Assuming that you want to use the fa-chevron-right icon, you simply need to target the list item via CSS. Use the :after pseudo-class: .list-item:after { font-family: FontAwesome; // or whatever the font awesome family is registered as content: '\f054'; } Edit So, to give an idea of how you might pass dynamic CSS (which can be easily adapted to a ...


4

Disclaimer: - This isn't actually an answer. - It is intended to help you with your additional research on the topic. - Furthermore it is reflecting a - at least felt - lately more frequent occurrence of similar questions regarding similar problems. Additional information regarding this topic on Wordpress Development: Removing Image Sizes for ...


4

The problem is that you can't distinguish form an anonymous function and another, so yes, it is possible to remove a closure (i.e. anonymous function) but if more than one closure act on same filter at same priority you have to make a choice, remove them all, ore remove only one (without knowing exactly which). I'll show how to remove them all using a ...


4

I am doing something like this in one of my plugins: function my_body_class( $c ) { global $post; if( isset($post->post_content) && has_shortcode( $post->post_content, 'your-shortcode' ) ) { $c[] = 'your-class'; } return $c; } add_filter( 'body_class', 'my_body_class' ); I'm not sure it was really necessary, but I ...


4

Is there more efficient ways to validate the quotes using the WordPress api? I think you should set a nonce for the form You also should check if current user has capability to save quote To get properly sanitize values form $_POST look at filter_input and/or filter_input_array I don't see performance issues on validation, but a possible ...


4

Redeclaring a function in a child theme only works when the parent themes' function is wrapped in a if( !function_exists( 'function_name' )): condition. Then you can simply just copy the complete function to the child theme and do whatever modifications you need to do. If the parent themes' functions aren't wrapped in that if conditional statement, and ...


4

The two functions output exactly the same thing. From the Codex entry for get_bloginfo(): 'name' - Returns the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table. From source: case 'name': default: $output = get_option('blogname'); Neither get_bloginfo() nor bloginfo() do any sort ...


4

Specifically editing the code you provided in the original question: add_filter( 'nav_menu_link_attributes', 'wpse121123_contact_menu_atts', 10, 3 ); function wpse121123_contact_menu_atts( $atts, $item, $args ) { // The ID of the target menu item $menu_target = 123; // inspect $item if ($item->ID == $menu_target) { $atts['data-toggle'] = ...


4

Basically every filter has to be registered in the original function code (since a filter is just a way you can overwrite what is happening in the default function). So before you can attach your custom function to a filter using add_filter() the filter has to be registered before with apply_filters() (there are other functions which do the same - but this ...


4

If it is a custom theme for your site then there would no great speed or security improvements by moving functions. On the other hand if you want to distribute the theme then I recommend having only the minimum php in the page templates files and having the rest of the functions organized in different files. I like the basic theme set up files of the theme ...


4

Checking to see if built in WordPress functions exist before calling them is for backward compatibility which IMHO is not needed. So if you see if ( function_exists( 'register_nav_menus' ) ) the theme author is supporting versions earlier than 3.0. You still sometimes see if ( function_exists( 'dynamic_sidebar' ) ) Why? I couldn't tell you because ...



Only top voted, non community-wiki answers of a minimum length are eligible