Tag Info

Hot answers tagged

5

Yes it is. It might get a bit clearer if you re-format this line $title .= " $sep " . sprintf( __( 'Page %s', '_s' ), max( $paged, $page ) ); to: $title .= " $sep "; $title .= sprintf( __( 'Page %s', '_s' ), max( $paged, $page ) ); The first parameter of sprintf expects a format which is here the return value of the __ function. The second ...


4

finely made its answer function wp_destroy_all_other_sessions() { $token = wp_get_session_token(); if ( $token ) { $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); $manager->destroy_others( $token ); } } add_action('init', 'wp_destroy_all_other_sessions'); You can use it on any plugin or direct you can ...


4

At the risk of getting voted down by everybody else here who thinks this is OK. I say: No, you shouldn't define functions in template files. This should be considered bad practice. Let's have a look at the documentation: Functions File Explained. The functions file behaves like a WordPress Plugin, adding features and functionality to a WordPress ...


3

get_currentuserinfo() is a pluggable function, it is not available during plugins load stage. That aside you shouldn't be adding filter conditionally, but use data provided by the filter. If you take a look at filter calls: apply_filters( 'auth_cookie_expiration', 14 * DAY_IN_SECONDS, $user_id, $remember ) $user_id is provided as second argument. You ...


2

OK, so I think I got everything that is needed. So yes, you could work with a combination of: plugins_api install_plugin_install_status install from an instance of Plugin_Upgrader This may seem elaborate but you can actually see from the WP-CLI project that it is quite straight-forward. Of course, you can just install that excellent plugin and be done ...


2

Before we go into details, it should be noted that the guides you are referring to is only what it is, a guide. Just like coding standards (which not even the core developers stick to :-)), the Wordpress Handbook is just a guide to developers, it is not the alpha and omega. The basic idea is to use this guide and implement these guideline in such a manner ...


2

You can adjust the attachment query in the media library popup, through the ajax_query_attachments_args filter. Here are two PHP 5.4+ examples: Example #1: Show only attachments that where uploaded during the last 24 hours: /** * Media Library popup * - Only display attachments uploaded during the last 24 hours: */ add_filter( ...


2

Sure. If your function is really just doing some control switching, putting it into the template is fine. Anything more than that traditionally goes into functions.php or similar. Edit: +10 at Pieter Goosen's mention of trying to keep things DRY. It can actually be difficult to keep things DRY with WordPress theming. I'm a fan of the Sage starter theme. ...


2

Plugins are loaded before the theme which means that your apply_filters won't have any actual callbacks registered to it. Instead, you need to call your apply_filters sometime after the theme has been loaded. Something like this: /* Your plugin's file: */ add_action( 'init', 'my_lovely_funky_filters' ); function my_lovely_funky_filters() { /* Fire our ...


2

I assume you mean fetching an external feed with an HTTP authentication. Fetching feeds with HTTP Authentication Note that fetch_rss() uses the MagPie library, that's deprecated in WordPress. Use instead fetch_feed() that uses the SimplePie library. It looks though it doesn't support this kind of url: http://user:pass@example.tld/feed/ like we can ...


2

Add another preg_replace. Something like: $text = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "", $text);


1

How can I make this code to display the meta tags at the top of the header section right after ? You probably can't. Typically wp_head() is called at the end of the </head> section, but that is theme dependent. You don't have any control. How can I put each meta tag on a separate line? Use double quotes and \n... $cjt = '<meta ...


1

I wanted to achieve the same thing.. What I ended up doing was creating a function that collects the Kirki variables (see here about the use of variables in Kirki) and writes them to a scss.. $file = get_template_directory() . '/sass/custom/_custom_vars_mixins_options.scss'; if(file_exists($file)){ $output = ""; $variables = ...


1

Just small nuggets of information that may help in simple setups (most notably the ones with no use plugins using ob_start): 1) You don't need the to put dns-prefetch calls as the first elements. What you need is to put them as soon as possible before any other element calling external resources. 2) Is actually possible to use negative numbers as priority ...


1

You can check for specific user role using following code - if (is_user_logged_in() && current_user_can('administrator')) {} The function current_user_can() takes role name as parameter. For more info - https://codex.wordpress.org/Function_Reference/current_user_can/


1

This is what I have used to create a custom order status called "Invoiced". Add this to your theme's functions.php // New order status AFTER woo 2.2 add_action( 'init', 'register_my_new_order_statuses' ); function register_my_new_order_statuses() { register_post_status( 'wc-invoiced', array( 'label' => _x( 'Invoiced', ...


1

Your syntax is slightly off in a few places. I'll try and let the code explain: function wpse_199498_meta_to_table( $post_id, $post ) { // Use the second argument of our hook, which is the post object if ( $post->post_type !== 'festival-event' ) return; global $wpdb; // Don't need to use $_POST, just use the functions as ...


1

There is no wrong or right way, neither is there any type of set rule or standard stating where custom code should go or not. This is all personal preference. There are few guidelines which you should use (if you want to) Templates (and all code for that matter) should be kept organised, maintainable, and easy to read and understand. Do not clot code ...


1

Add the filter "ajax_query_attachments_args" in this way and URLs variables are sent to the class WP_Query the default is to send array(7) { ["orderby"]=> string(4) "date" ["order"]=> string(4) "DESC" ["posts_per_page"]=> string(2) "40" ["paged"]=> string(1) "1" ["post_type"]=> string(10) ...


1

I'm listing down the necessary hooks which will add, validate the custom fields on registration form as well as allow fields update from user profile page - //show field on WordPress registration form add_action('register_form','register_form_callback'); //handle validation add_filter('registration_errors', 'registration_errors_callback', 10, 3); //save ...


1

First of all, you are using $rinter as a number and at the same time as an URL for the anchor element. Secondly, the href attribute requires mentioning the protocol (http(s):// for example) in front of the domain or else it will just be relative to the current viewing address. ($rinter should be something like http://www.w3.org instead of just www.w3.org)


1

As I have stated in comments, this will take some work. In short, you will need the following: Get all the terms from the style taxonomy. Here we would only want the term ids Get the current tax_query from the colour taxonomy. Use each term from the style taxonomy and create a new tax_query to get posts from the current page's term and the term being ...


1

My problem got solved by commenting the some codes in function.js(theme js folder) that generating "Expand child menu" text.


1

There's an array option when creating a custom post type and custom taxonomy for ""rewrite"" and you can set a ""slug"" and it's there that you can change your permalink structure. For more read here. Also the other option that I get from post 1 and post 2 one helped me blink some idea. 1 Rewrite rule: You need to add a new rewrite rule so Wordpress knows ...


1

I got it to work as follows -- in mu-plugins directory, my superAdmin.php script looks like this: <?php function check_for_superAdmin($user_login, $user) { $current_user = get_userdatabylogin($user_login); if ( is_super_admin( $current_user->ID ) ) { // do these things } else { // do other things } } add_action( 'wp_login', ...


1

So, you're using wp_localize_script to inject the ajax url. But you didn't use the localized var handle to access that value. Try this: /* ... */ $.ajax({ url: ajaxStuff.ajaxurl, // NOTE use of 'ajaxStuff' object /* ... */


1

The best way to customize a navigation menu is to use a custom 'walker' function.. Here are the steps how to achieve the customization that you want! Create a "wp-custom-nav-walker.php" file in your theme directory for a new custom 'walker' class. Extend the Walker_Nav_Menu class and copy the class' function that you want to modify and override it in the ...


1

when ("#edit").click( is called, the element "#edit" doesn't exist so the .click( cannot be attached solution 1 you call click( juste after .innerHTML = response solution 2 use delegated event like that : $("body").on("click", "#edit", function () {...


1

You can use the WordPress function is_user_logged_in() to check that, and create some basic if statements to show and hide the appropriate code.


1

It seems that the OP have managed to solve his/her problem by doing this, which can be found at Different menus for logged-in users. if ( is_user_logged_in() ) { wp_nav_menu( array( 'theme_location' => 'logged-in-menu' ) ); } else { wp_nav_menu( array( 'theme_location' => 'logged-out-menu' ) ); } The more shorter way to achieve that is by ...



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