Tag Info

New answers tagged

0

The problem is not version_compare, the problem is that register_activation_hook is just a shortcut for add_action( 'activate_' . $file, $function ); where $file is plugin_basename( __FILE__ ); and __FILE__ is your main plugin file absolute path. So, what your code does is to call dw_deactivate_theme_options() when the action 'activate_' . $plugin is ...


2

Yep, wp_trim_words(): <?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?> Or in your case: <?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 55 ) ); ?>


1

The CSS for my parent theme (core) was incorrectly formatted. The code at the top read: Theme Name: Core Theme URI: http://www.domain.co.uk Description: The core theme. Author: Squideyes Author URI: http://www.domain.co.uk Template: Core Version: 1.0.0 Tags: clean, simple, easy The Template: tag should only appear in the child theme css. This is what ...


1

You can use the awesome WP_Admin_Bar & hook in with admin_bar_menu: /** * Add a "Log out" link directly to the admin bar. * * @link http://wordpress.stackexchange.com/q/141446/1685 * * @param WP_Admin_Bar $wp_admin_bar */ function wpse_141446_admin_bar_logout( $wp_admin_bar ) { if ( is_user_logged_in() ) { ...


0

I would use the action wp_footer. You could do something like below. You do not need to loop through all posts whenever a post is showing. Just add the current post score to user for the current post. add_action('wp_footer', 'wpse55725_update_user_score'); function wpse55725_update_user_score(){ if( !is_singular('post') ) return; // only ...


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


0

Lead dev of Redux here. If you declare global $redux_global in your header.php file, it will be accessible by all other template files within your theme. You can also use $GLOBALS['redux_global']['css-block'] to bypass the need for $global $redux_global.


0

In order for it to save the data you need to hook your validate_dw_quote() onto to an action, such as admin_init or init. add_action('admin_init', 'validate_dw_quote');


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


1

Got it, after making a Custom Shortcode (this can be found on standard WP docs), then by direct calling one of JW player's function, from the Template File, like: generate_playlist( '1234' ); It will then return a complete Array of the JW Playlist Object, so we can parse it out.


0

After some research I came to conclusion that this splash screen will destroy the website SEO and the usability, so I have decided not to add this kind of page.


1

There are a lot of ays to do the trick, one possible is use a function that use a static variable. However, before you can be able to get the arguments set in shortcode, the shortcode must be processed... function foobar_func( $atts = array(), $out = FALSE ){ static $args = array( 'foo' => 'default foo', 'bar' => 'default bar' ); ...


0

Its stored in a single file called quote.php Assuming that means that your plugin is stored in wp-content/plugins/quote.php, then the problem is that your code is hard-coded to submit to wse140202.php-- presumably you cribbed some code from another question here. In other words, this line: add_menu_page('Quotes Settings', 'Quotes Styling', ...


1

Per the Codex: relation (string) - The logical relationship between each inner taxonomy array when there is more than one. Possible values are 'AND', 'OR'. Do not use with a single inner taxonomy array. So you are on the right track, but your tax_query is wrong. relation is part of the outer tax_query array and not part of the top level query ...


1

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


0

You just need the last part of your function where you switch to blog 1 and get the menu. function wp_multisite_nav_menu() { $args = array( 'menu' => 'Main Menu', 'theme_location' => 'main-nav' ); switch_to_blog( 1 ); echo wp_nav_menu( $args ); restore_current_blog(); }


2

If you hook your localize script function to wp_enqueue_scripts, then you will have access to the global $post variable. As long as you pick a hook at or after 'wp' you should have access to the global $post. <?php add_action('wp_enqueue_scripts', 'YOUR_NAME_scripts'); function YOUR_NAME_scripts() { wp_enqueue_script('YOUR_NAME-js'); ...


2

If you check the source ... 1361 /** 1362 * Allows a theme to register its support of a certain feature 1363 * 1364 * Must be called in the theme's functions.php file to work. 1365 * If attached to a hook, it must be after_setup_theme. 1366 * The init hook may be too late for some features. 1367 * 1368 * @since 2.9.0 1369 * @param string ...


3

add_theme_support( $feature, $arguments ); as you can see have two parameters, $feature and $arguments. $feature is the feaure you need to add theme support for. This parameter doesn't accept an array, only a string. So you would have to add a add_theme_support for every feauture that you would like to include in your theme. In your question, it is ...


3

You need to use one add_theme_support() call for each feature. Per the Codex, the proper function call is: add_theme_support( $feature, $arguments );


2

Scripts and stylesheets should always be loaded in the head or in the footer via the wp_enqueue_scripts action hook. wp_enqueue_scripts is the proper hook to use when enqueuing items that are meant to appear on the front end The init hook executes before wp_head which is to early for script to load in the header. The wp_enqueue_scripts action hook is ...


2

You should first load your scripts with a hook on wp_enqueue_scripts like this for example : add_action( 'wp_enqueue_scripts', 'load_my_scripts' ); function load_my_scripts() { wp_enqueue_script( 'jquery' ); } What I like to do is, register my script with a hook on init and then enqueue them with a hook on wp_enqueue_scripts: // Register Scripts ...


1

I would just filter the_title: function wpse140502_filter_page_title( $title ) { // only do something on static pages // and on the main query if ( is_page() && is_main_query() ) { // let's see if the current page has a parent global $post; if ( 0 != $post->post_parent ) { // Set this to whatever ...


0

You could just output the header around the title without using the $before and $after parameters: if ( get_the_title() ) { global $post; echo '<header class="entry-header"><h1 class="entry-title">'; echo get_the_title() . ' - ' . get_the_title( $post->post_parent ); echo '</h1></header>'; } If you insist on ...


1

You can just add a check: if ( ! empty ( $post->post_parent ) ) { $parent_title = get_the_title($post->post_parent); echo "<h1>$parent_title</h1>"; } or use setup_postdata(): setup_postdata( $post->post_parent ); the_title( /* arguments here*/ ); wp_reset_postdata();


0

For me what worked was this: <?php wp_nav_menu( array( 'container' => '', 'items_wrap' => '%3$s' ) ); ?> Hope it helps.


0

I would store the array to the options able as a serialized value. update_option('dw_quotes', serialize($quotes)); and retrieve with: $quotes = get_option('dw_quotes', null); if ($quotes !== null) { $quotes = unserialize($quotes); } Other things to consider: Add handling in case the quotes option does not exist. Also add handling to delete quotes ...


0

This is an easy fix by simply using $_REQUEST instead of $_GET in your hidden field for register_form. More importantly, you should be sanitizing the field before you echo it, otherwise you're wide open to injection and CSRF: <?php if ( isset( $_REQUEST['role'] ) ) echo esc_attr( $_REQUEST['role'] ) ?>


2

It's certainly possible but you're probably looking at doing an ajax request on the image click which in turn executes the short code and returns the output. This involves three distinct steps, binding the ajax request to an action, executing the ajax request and handling the response, and actually writing the script that will process the request. This ...


3

When you pour some water into a glass, first you put the glass on the table, then you turn the bottle. If you first turn the bottle, and then put glass on the table, your floor gets wet and your glass stay empty. Actually wp_enqueue_scripts is just a way to save a variable (water) inside a global object (glass), so before to call the function (turn the ...


2

It is required, actually. There's no real difference between themes and plugins as such. Neither of them should take actions on merely being loaded, they should use action hooks on functions to have things happen in the correct ordering.


1

It is not a direct answer for your problem. But I will help you to make image according to your need. When you use add_image_size it does not resize the existing images. it only works for the new images that will be uploaded after adding your add_image_size function. So your code will not generate new images for is_page_template function. But you can use ...


1

1) create one template page on your page-templates dir in landingpage.php with this code page-templates/landingpage.php <?php /** * Template Name: Landing page */ ?> <div id="main-content" class="main-content"> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> ...


1

If you really want to execute code stored in a database, a quick google search reveals that you can use the eval() function to do just that. However, many people do say that Eval is Evil... Instead of storing the entire PHP code of an option in the database, try storing a simple boolean flag for your option and then test whether to get your template's ...


2

As @gate_engineer already stated, your problem is a plain PHP problem where you are trying to access an Object as Array. To not only state that, but help you a bit further, the correct check for a proper response object is checking against the return value of wp_remote_retrieve_response_code() and wp_remote_retrieve_response_message(): $response = ...


1

References: wp_remote_post() The WP_Error Class Stopping the Fatal Error: The error that you're receiving above is due to the fact that wp_remote_post() returns a WP_Error object if a request to the remote web server failed. When the script executes the next expression on line 63: if ( $response['response']['code']!='200' ) ...PHP gets confused as to ...


1

I know this is kind of a backwards way of doing it, but I suppose if you disable the possibility to upgrade the plugin, then you don't need to worry about the plugin being overwritten. Change the plugin version number (in the plugins main file comment header) to something ridiculously high so it won't recommend an upgrade to the user. I've had to do ...


2

If you want to create thumbs on the fly you can use Aqua image resizer, But there is a drawback of this mini script. The created thumbs will not delete upon deleting image from library. But its not a big deal. If required you can do so via SHH commands


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


7

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


1

The following gets called by WordPress while getting the reply link. apply_filters( 'comment_reply_link', $before . $link . $after, $args, $comment, $post ); Use a custom filter to provide your own link. I don't believe there is a direct way of altering just the URL, you have to inject the url into an html string yourself. add_filter( ...


0

function mytheme_setup() { // Set default values for the upload media box update_option('image_default_align', 'center' ); update_option('image_default_link_type', 'media' ); update_option('image_default_size', 'large' ); } add_action('after_setup_theme', 'mytheme_setup');


1

The default image size for inserting images is stored in the options table in image_default_size. You can change the default image size by updating the option: update_option( 'image_default_size', 'large' ); Role-dependent default image size To change the default image size for contributors only, you could hook into pre_option_[option] filter (which is ...


0

A friend pointed out how to solve this. If anybody else runs into the same issue as me, this is the correct code. // Custom shortcode, to query tracklistings. function custom_query_shortcode($atts) { // Defaults extract(shortcode_atts(array( "the_query" => '' ), $atts)); // de-funkify query $the_query = preg_replace('~&#x0*([0-9a-f]+);~ei', ...


0

You simply need to query your custom fields and return them with your shortcode: // EXAMPLE USAGE: // [loop the_query="showposts=100&post_type=page&post_parent=453"] function custom_query_shortcode($atts) { // Defaults extract(shortcode_atts(array( "the_query" => '' ), $atts)); // de-funkify query $the_query = ...


0

First of all why you would need custom query for this basic functionality to get users, when WordPress has inbuilt function get_users(). Anyway for custom query, table name is defined as function custom_func(){ global $wpdb; $getTest = "SELECT * FROM $wpdb->users LIMIT 1"; $arrayReturned = $wpdb->get_results($wpdb->prepare($getTest)); } It's ...


0

Looks like it is a privilege thing: Adding those tags as an admin works, while with other users having less privileges (editor, etc) does not.


1

What if you add your filter, with the priority 11, so it goes after? That's ugly, but might work in your case. add_filter( 'manage_edit-comments_columns', function( $default ) { unset( $default['smr_comment_rate'] ); return $default; }, 11, 1 );


1

Okay, so I used this code to only display "wrestler" post type & it worked. I mixed mine & Pieter Goosen's code to get this out: add_filter( 'dashboard_glance_items', 'custom_glance_items', 10, 1 ); function custom_glance_items( $items = array() ) { $post_types = array( 'wrestler' ); foreach( $post_types as $type ) { if( ! ...


0

the_content_rss() is deprecated. You should be using the_content_feed(), but that is a secondary problem. Both functions echo content. What you want is the get_* variant-- get_the_content_feed(). That is a general rule, by the way, but not a 100% consistent one. Many functions starting with the_ will output content immediately and there tends to be a get_ ...



Top 50 recent answers are included