Hot answers tagged

27

style_loader_tag style_loader_tag is an official WordPress API, see the documentation: https://developer.wordpress.org/reference/hooks/style_loader_tag/ apply_filters( 'style_loader_tag', $html, $handle, $href, $media )Filters the HTML link tag of an enqueued style. First enqueue your stylesheet, see documentation: https://developer.wordpress.org/...


19

Here is a working solution (tested as is) The HTML (could be part of page content) <input type="text" name="keyword" id="keyword" onkeyup="fetch()"></input> <div id="datafetch">Search results will appear here</div> The JavaScript ( goes to your theme's functions.php ) // add the ajax ...


17

How to prevent the WordPress admin bar from overlapping with your Twitter Bootstrap navigation bar. In response to: WordPress admin bar overlapping twitter bootstrap navigation Asked by: @TheWebs If you are using Twitter Bootstrap with WordPress and have an issue with the WordPress admin bar overlapping with your navigation bar, you're probably pretty ...


15

Yes it is possible. There are two ways that I can think of at this moment. First follow what the codex says Shortcodes. Basically you just wrap your html in ob_start(); this will return the html as a string so you can echo it. function my_shortcode() { ob_start(); ?> <HTML> <here> ... <?php return ob_get_clean(); } The ...


12

The value for that string is normally taken from the option WPLANG in your database table $prefix_options. You can set it in the backend under Settings/General (wp-admin/options-general.php) or per SQL. There several ways to change that value per PHP: Create a global variable $locale in your wp-config.php: $locale = 'en_GB'; Declare the constant WPLANG ...


11

Ok, so I think I may have come to a solution. It doesn't seem as nice and easy as I'd like it to be, but then again major modifications to default Wordpress functionality sometimes requires drastic measures. :) This is my working solution to rewriting the HTML output for post thumbnails throughout my site to work with the Retinise.js plugin. Of course this ...


10

Menu locations are defined in functions.php You can read the codex for more information on how to define menu locations in functions.php Register Menus Firstly, in your theme's functions.php, you need to write a function to register the names of your menus. (This is how they will appear in the Appearance -> Menus admin screen.) As an example, this menu ...


9

This was very frustrating to figure out. I spent hours on this issue and discovered your problem is in this input: <input type="text" name="name" id="name" size="30" value=""/> Try changing the input field name to anything but "name", for example: <input type="text" name="user_name" id="name" size="30" value=""/>


8

It looks like your site's title is empty. Fill it out or try for example: add_filter( 'wp_title', function( $title ) { return trim( $title ); } ); to remove the blank space in front. For your setup, the following part of wp_title() is responsible for the blank space: $title = $prefix . implode( " $sep ", $title_array ); So when you're on a single ...


8

I was able to make it work by adding these two lines to my theme's functions.php file: add_filter( 'widget_text', 'shortcode_unautop'); add_filter( 'widget_text', 'do_shortcode'); The Custom HTML Widget now correctly executes the shortcode function and outputs the result.


7

Today there is a native option to do this without hacking the core, or doing tricky filters with output buffer. You just need to use the filter 'comment_form_defaults' and edit the values from 'title_reply_before' and 'title_reply_after' key: add_filter( 'comment_form_defaults', 'custom_reply_title' ); function custom_reply_title( $defaults ){ $defaults['...


7

/** * Get custom header's alt data. * * @link http://wordpress.stackexchange.com/q/151850/1685 * * @return string */ function wpse_151850_get_header_image_alt() { $attachment_id = 0; if ( is_random_header_image() && $header_url = get_header_image() ) { // For a random header, we have to search for a match against all ...


7

As always, people copy paste whatever they learned from and IIRC the first style is the coding style of wordpress core. As you said yourself, when there is a big block of generated HTML it is easier to look at (and balance tags) under the first style, but pragmatic people will use the second whenever that is not the case. It is really just coding style ...


7

You are looking for wp_kses(). https://codex.wordpress.org/Function_Reference/wp_kses There are more helper functions like wp_kses_post() and wp_kses_data()


7

You'd better never disable those actions (what you say). Instead, insert add_filter('the_content', 'MyFilter', 88 ); and create such function: function MyFilter($content){ $tags = array( 'p', 'span'); /////////////////////////////////////////////////// ///////// HERE INSERT ANY OF BELOW CODE ////////// ///////////////////////////////////////...


6

The main differences are: the first snippet has html inside php while the second one has php inside html. Both approaches are basically valid, both are fine. I would however always prefer (and recommend) to have php inside html because chances are that a third person / designer might have less difficulties in understanding the code and i.m.h.o. it is less ...


6

Make use of the the_content filter. This way you can adjust/add/remove certain stuff from the content add_filter( 'the_content', function ( $content ) { // Make sure we only target the main query's content, adjust as needed if ( !in_the_loop() ) return $content; // We are targeting the correct content, so lets add what we need to $...


6

I found out a way that you can place any text. You just need to create an array where you want the paginate_links to appear. <!-- Put this in your functions.php --> <?php $args = array( 'base' => '%_%', 'format' => '?paged=%#%', 'total' => 1, 'current' => 0, 'show_all' ...


6

The best way would be to create a custom plugin for your site. Take a look at the plugin handbook to get started https://developer.wordpress.org/plugins/ In the plugin, you can just put the libraries in a folder, and include them in your main plugin code. Your plugin can then do one of these Register a shortcode Create a custom template tag, which would be ...


5

Yes, you'll need to implement the walker class for this. Here is a simple example. $defaults = array( 'theme_location' => 'primary', 'container' => 'ul', 'menu_class' => 'nav navbar-nav main-nav', 'walker' => new Primary_Walker_Nav_Menu() ); wp_nav_menu( $defaults ); In the above block of code, the ...


5

The security risk here is not about the plain text but about translation. You should note that esc_html_e is not only a function for escaping HTML but also for localization (l10n). I.e. other people can translate this String but you don't know what the translation would be. It is possible that somebody translates the String and adds a link or some malicious ...


5

shortcodes are not allowed in html attributes, shortcodes are not programing language, they are place holders to proper html content.


5

Hope this helps someone: Instead of doing this: <a href="https://example.com/folder/edit.php?action=someaction&id=[foocode parameter='value']&edittoken=[foocode parameter='othervalue']">linktext</a> You can do this: [foocode parameter1=value parameter2=othervalue] and then do this: add_shortcode( 'foocode', 'prefix_foocode' ); ...


5

This code will allow you to customize the comment field labels and will move the comment form below the fields. Add the code to your functions.php or to a plugin. To change the labels, modify the Name CUSTOMIZED, Email CUSTOMIZED, and Website CUSTOMIZED, and Comment * CUSTOMIZED text. /** * Customize comment form default fields. * Move the comment_field ...


5

Note This answer was originally included in @bitstarr's question above and was included as a separate answer here to comply with WPSE's Q&A model. Maybe someone else will have this issue and so i will share my solution here with you folks. function make_mce_awesome( $init ) { /* There are easier things than make 'left/center/right align ...


5

TLDR; Nested shortcodes cannot have the same name. You must have unique names for shortcodes within shortcodes. I've found the answer thanks to @patnz in response to: shortcode inside another shortcode. If you look at the WordPress Codex :: Shortcode API :: Nested Shortcodes you will find the answer with an illustrative example. So in my situation, as a ...


5

By default, WordPress sets various classes to <body> depending on which page, template, parent, .. you are on. For a single post, some of these are single and single-post, so you could use the following body.single.single-post .post-meta { margin-right: 0px !important; }


4

For what it's worth, shortcodes that don't accept any parameters appear to work in HTML tags. It's the ones that have parameters that don't. Ex: <a href="https://example.com/folder/edit.php?action=someaction&id=[foocode parameter='value']&edittoken=[foocode parameter='othervalue']">linktext</a> doesn't work Ex: <a href="https://...


4

First of all, either quotes are as good as each other. See this question There is no way you can do this with a plugin, action or filter. To achieve this you will have to do this manually by using the "find and replace" option on your IDE. I do not advise you to do this as: You may end up breaking your WordPress core You will lose all changes next ...


4

The get_search_form() echos so it will always show up before returns. Use: get_search_form( false )


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