Tag Info

New answers tagged

0

While writing the question in SE I found already the solution: add_filter( 'get_the_excerpt', 'get_custom_the_excerpt' ); function get_custom_the_excerpt($excerpt) { $post = get_post(); $format = get_post_format( $post ); // modify excerpt if it is a quate, for example set title as author if ($format == 'quote') { $output = ...


0

wp_update_term there should be 3 parametrs: $term_id, $taxonomy, $args, you'r not specifying taxonomy..


0

Or this more compact one will do the same : add_action( 'admin_bar_menu', 'remove_some_nodes_from_admin_top_bar_menu', 999 ); function remove_some_nodes_from_admin_top_bar_menu( $wp_admin_bar ) { $wp_admin_bar->remove_menu( 'customize' ); } Regards


0

The code that worked for me was the following: <? $the_query = new WP_Query( 'page_id=1086' ); while ( $the_query->have_posts() ) : $the_query->the_post(); the_title(); the_content(); endwhile; wp_reset_postdata(); ?> I found this on a thread here


3

These queries are in the wp_enqueue_media() function: $has_audio = $wpdb->get_var( " SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'audio%' LIMIT 1 " ); $has_video = $wpdb->get_var( " SELECT ID FROM $wpdb->posts ...


0

You can write a small custom function, that loop about the network and add in each site of the network the new role. See the source below als example to add_role. If you like update or change a existing role, then switch from add_role to add_cap. function fb_change_role_network_wide( $role ) { global $wpdb; $args = $args = array( ...


2

customize should work. I was able to remove the Customize link with the following code: add_action( 'wp_before_admin_bar_render', 'wpse200296_before_admin_bar_render' ); function wpse200296_before_admin_bar_render() { global $wp_admin_bar; $wp_admin_bar->remove_menu('customize'); }


0

solved my problem by removing <?php query_posts('posts_per_page=3') ?> and tried limiting posts from Settings->Reading. Thanks


0

When using wp_nav_menu you can pass arguments to it which help you style the output, look at: $container Whether to wrap the ul, and what to wrap it with. Allowed tags are div and nav. Use false for no container e.g. container => false . $container_class the class that is applied to the container. $container_id The ID that is applied to the container. ...


8

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 ...


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 ...


0

There is no practical or theoretical problem with placing functions in home.php as long as they are being used only in that file. You might be able to use them in other contexes as well, but then it will become bad coding. In principal any function that is called from two different template files should be in functions.php (or in a file included by it), the ...


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. ...


0

Try this.. This is a pretty basic code and you might need to modify it to get it fully work, but it will get you started. function load_testimonials( $atts ) { extract( shortcode_atts( array( 'id' => '', ), $atts ) ); $out = '<div id="testimonials" class="flexslider">'; $out .= '<ul ...


0

Try use this (functions.php) : function product_title($id) { $custom='CustomField' return get_post_meta($id, $custom, true); } and call func in your template (in loop and etc...): <?php $p_title=product_title(get_the_ID()); ?> <h3>Product : <?php echo ($P_title); ?> </h3>


0

It should work <?php $my_postid = 1772;//This is page id or post id $content_post = get_post($my_postid); $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]&gt;', $content); echo $content; ?>


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

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 = ...


0

if the modification is called in the action admin_menu you can come just after, in order to correct the menu with some code like this : add_action("admin_menu", function () { $parent_file = 'parent.php'; $full_url = add_query_arg( 'action', 'action-name', admin_url( 'users.php' ) ); global $submenu; // searching the last submenu ...


0

The code you are seeking for is located in the wp-admin/includes/class-wp-upgrader.php. There is a bunch of classes regarding all updates.


0

If I understand what you want I would call it on the save_post hook: https://codex.wordpress.org/Plugin_API/Action_Reference/save_post So the code would be something a little like: function wphuyeh8_save_post_tag( $post_id, $post, $update ) { // If example is set and not false if($_REQUEST['_example']): // set the tag ...


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 ...


0

just use the function get_avatar, $default is for your custom default. <?php echo get_avatar( $id_or_email, $size, $default, $alt, $args ); ?> https://codex.wordpress.org/Function_Reference/get_avatar


2

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


0

Photoshop also uses application/x-photoshop. I imagine it varies from version to version.


0

In your query, you'll see: AND .ID IN (SELECT 'post_id' FROM 'lat_lng_post' WHERE (. The actual posts table name is missing from the query. The problem is you are missing the $ from your declaration of wpdb. global $wpdb.


0

Not sure about DB connection but there seems some syntax issue. lat and lng have been used unlike PHP variables at some places in your code. I believe, they should have been $lat and $lng respectively instead.


0

As per documentation on wp_remote_get() it doesn't return you just the body of requested resource. Its return will be either the array of data or WP_Error object on failure. The simplest snippet to get to the body would be: $json = wp_remote_retrieve_body( wp_remote_get( $url ) ); PS it's kinda weird to be doing this in shortocde, are you sure it's most ...


0

First, this line if ( 'location' != $_POST['festival-event'] ) should be if ( 'festival-event' != $_POST['post_type'] )


0

You can simply add those CSS to admin HEAD section, it's fast and easy solution. function jrl_styles() { ?><style type="text/css"> #jrl-wrap { width: 700px; padding: 3em; /* ... */ } </style><?php } add_action('admin_head', 'jrl_styles'); Or you can enque your CSS file like this: function ...


0

This answer was given me to elsewhere, however thought i'd share just in case anyone has similar issues: function save_lat_lng( $post_id ) { global $wpdb; global $post; $custom_lat = get_geocode_lat( $post_id ); $custom_lng = get_geocode_lng( $post_id ); // Check that we are editing the right post type if ( 'festival-event' != ...


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 ...


0

If you can wait for the parent theme's functions.php to load you can hook to the after_setup_theme or init actions and do what you need there.


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', ...


0

Since it's a standalone script, you can just link to it directly and WordPress will be none the wiser. Just make sure you get the link right - if it's in your theme, it will be something like: http://example.com/wp-content/themes/my-theme/generate-pdf.php Don't hardcode the URL though, use the available template functions: <a href="<?php bloginfo( ...


0

OK perfect. There was a syntax error in this line: <?php if( 1 == $blog_id ); ?> replaced: <?php if( 1 == $blog_id ): ?> close post.


0

I have write : <?php $blog_id = get_current_blog_id(); ?> <?php if( 1 == $blog_id ); ?> <div id=""><script src=""></script><script src="" ></script></div> <?php elseif( 2 == $blog_id ): ?> <div id=""><script src=""></script><script src="" ></script></div> ...


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/


0

You can make WordPress query for a certain user role by using current_user_can("role_name"). Thanks to Mayeenul Islam for providing the solution!


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

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 ...


0

This is the correct method - except the function is apply_filters, not apply_filter. Hence your error.


0

You are getting that because the $post variable isn't set. You'll need to call global $post at the beginning of your function. function custom_content_filter_the_content( $content ) { global $post; ...


0

The code contained the line add_action( 'admin_init', 'my_admin' ); at the end, but my_admin wasn't declared anywhere. Changed it to all_post_types, my function to register all the custom post types at once and it worked.


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) ...


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( ...


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

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 ...


0

Did you try hooking a bit later? add_action('template_redirect' , 'prevent_profile_access'); References: https://codex.wordpress.org/Plugin_API/Action_Reference https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect


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 ...



Top 50 recent answers are included