Hot answers tagged

5

Does it need it? Probably not (other than this edge case, props @bravokeyl). Should you add it? In my opinion, yes: From a coding/architecture POV, you're declaring "this file needs WordPress". Any direct hit to one of your theme's files (curious users, bots, "script kiddies" etc.) has the potential to leak a little bit of info (most likely filesystem) and/...


4

I see a couple of problems here. This line if (!is_admin() || 'default' != $domain) return $translated; returns the Howdy right back unchanged if is_admin is false - which it is if you're not in the dashboard. Also, you're running your filter callback on gettext. This means it will be run every time some internationalized content is used, which is ...


3

What I was looking for was transition_post_status. The documentation can be found here. What I did was to add one more filter add_filter('transition_post_status','myFunction');


3

Gallery Image Caption - As Title Of The Post It's attached To Here's one way to do it with a custom parent_titles attribute in the native gallery shortcode. This can be achieved by setting suppress_filters to false for the gallery query and modify the posts excerpts through the the_posts filter. We can then check for the custom attribute inputs through ...


2

If I understand you correctly you want to change the subject line of the email. The hook of your code only changes the content of the e-mail. There's a different hook for the subject: add_filter('comment_notification_subject', 'wpse_228315_comment_notification_subject'); function wpse_228315_comment_notification_subject($subject, $comment_id){ return "...


2

Try get_image_tag filter: add_filter('get_image_tag', function($html, $id, $alt, $title, $align, $size) { return $html . '<div>some piece of code here</div>'; }, 10, 6); References: get_image_tag() get_image_send_to_editor() wp_ajax_send_attachment_to_editor()


2

You also need to include the RTL.css file which is in the theme too: add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); function my_theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'rtl-style', get_template_directory_uri() . '/rtl.css' ); } To use the rtl.css from ...


2

You really shouldn't be doing this. Functions belong in the functions file. Period. (Or perhaps in a separate functions file which you include in the main one) However, if you insist, you can drop functions in any template file you want, because PHP doesn't care. Actually you will need to include it in every template file where you want to call ...


2

If you mean to attach it to any and all $_POST inputs in WordPress that's probably falls under Bad Ideas. WordPress has some kinks in how it works with that data (for example it emulates "magic quotes" mode, long deprecated in PHP itself) and some cases of POST in WP are extremely heavy (saving menus in admin for example). You can (and should) sanitize data ...


2

checked() will echo the result by default. That's the problem. To concat, you need to disable echo functionality by specify third param to false: echo '<input type="checkbox" id="my_meta_box_check1" name="my_meta_box_check1" ' . checked( $check, "on", false ) . '/>';


2

Samuel Elh correctly answered this. if ( $type === 'portfolio' ) { $terms = get_the_term_list( $post->ID, 'royal_portfolio_cats', '', $separator ); $term_array = explode(',',$terms); if ( $limit = array_slice($term_array, 0, $max = 5) ) { echo implode( ", ", $limit ); if ( count( ...


2

No, functions.php would generate PHP fatals if loaded directly as it uses the WordPress API. If functions.php tried to bootstrap and load WordPress however, then yes, it would be necessary, but if you've done that then something has gone horribly wrong and you need to start from scratch


2

Most of the times there is no need to check for defined( 'ABSPATH' ) in the child theme.


2

get_template_directory_uri() will always return the URI of the current parent theme. To get the child theme URI instead, you need to use get_stylesheet_directory_uri(). You can find these in the documentation, along with a list of other useful functions for getting various theme directory locations. If you prefer to use a constant, then TEMPLATEPATH is ...


1

When you are concatenating string you shouldn't use ;after the method. Also you should close que quotes, call the method, and open again. Try the code below: $listItem .= '<div id="agenda-block-image-responsive" style="' .get_field('speaker-img' ) . '">';


1

function custom_function_redirect() { if ( isset( $_GET[ 'link' ] ) && $_GET[ 'link' ] != '' ) { wp_redirect( $_GET[ 'link' ], 301 ); }else{ die('test'); } } add_action('template_redirect','custom_function_redirect'); Try this it worked for me. For redirection you should hook the function in template_redirect


1

The hook to use is wp_enqueue_scripts instead of wp_print_scripts


1

Looking at the id's in your rendered code, the name of your parent style seems to be 'basic-css'. That would mean you need array('basic-css') as the dependency in your wp_enqueue_style. However, in the code the child style seems to be called 'defaultbasic-css', while you enqueue it as 'child-style'. So it looks like there is some relevant code missing.


1

As suggested in the comments, these kind of modifications would be better served with a custom plugin, as they are not theme dependent. Here's an example: <?php /** * Plugin Name: Remove Footer Text * Description: Remove admin footer text and update footer text through filters. * Version: 0.0.1 * Author: Name * Author URI: http://example....


1

If you will not pass that how many arguments you need in your callback function then add_filter will provide you only one and first argument. Because default arguments for add_filter are add_filter ( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 ); $accepted_args is 1 if you do not pass it. Thus $args is always ...


1

More than likely this is an issue with the register_sidebar() call in functions.php. Look for before_widget and after_widget. The code below is the default usage. 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', Note: This will alter all of the widgets within the sidebar, not just the TextWidget.


1

Choose the right place in (rendering-)time First off, you are hooking at init, while you want to add your callback on wp_enqueue_script. Example: add_action( 'wp_enqueue_script', function() { wp_deregister_script( 'jquery' ); // Rest of logic } ); Staying up to date with core Also, you might want to use the correct version that core uses. I ...


1

The cookie is stored on the user's computer. The page is generated on the server. Somehow, you must make sure the cookie is transported back to the server when the user clicks on a link to fetch a second page. The instrument for this is javascript. You must send a script with the page that reads the cookie and adds the cookie content as a query_var to any ...


1

I wonder if you mean to register a file-less template with the theme_page_templates filter like this: /** * Add a file-less page template to the page template dropdown */ add_filter( 'theme_page_templates', function( $page_templates, $wp_theme, $post ) { // Edit this to your needs $fileless_theme_slug = 'my_fileless_page_template'; $...


1

I still run into the desire to do this kind of thing and have settled on the following solution which I proposed in the OP and like for a couple reasons: It's very transparent and feels consistent with keeping the logic in the theme. It makes it very easy to customize a template later if needed. Custom Template Here's the entire template file if I don't ...



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