Skip to main content
31 votes
Accepted

How to add crossorigin and integrity to wp_register_style? (Font Awesome 5)

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, $...
Remzi Cavdar's user avatar
  • 1,186
23 votes
Accepted

ajax live search for post title

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()"></...
Ahmed Fouad's user avatar
  • 1,353
14 votes

How to escape html code with html allowed

You are looking for wp_kses(). https://developer.wordpress.org/reference/functions/wp_kses/ There are more helper functions like wp_kses_post() and wp_kses_data()
Jory Hogeveen's user avatar
11 votes
Accepted

How can I make my custom shortcode work in a Custom HTML Widget?

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 ...
Pikamander2's user avatar
9 votes

How do we remove the H3 tag for the reply-title I.D

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 '...
Felipe Araujo's user avatar
7 votes
Accepted

strip only specific tags (like <p>), but keep other tags (like <br/>)

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', '...
T.Todua's user avatar
  • 5,810
7 votes
Accepted

Modify previous and next text from pagination links

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( '...
Gabriel Souza's user avatar
6 votes

How do I use Shortcodes inside of HTML tags?

shortcodes are not allowed in html attributes, shortcodes are not programing language, they are place holders to proper html content.
Mark Kaplun's user avatar
  • 23.4k
6 votes

How do I use Shortcodes inside of HTML tags?

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']&...
Máximo Obed Leza Correa's user avatar
6 votes

Where should I install a PHP library into WordPress so that code in a webpage can activate it?

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 ...
Kavya Gokul's user avatar
5 votes
Accepted

customize comment form

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 ...
Dave Romsey's user avatar
  • 17.8k
5 votes

Snippet: Use classes instead of inline styles for text alignment

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 ...
cjbj's user avatar
  • 14.8k
5 votes

How to add html attributes to the "ul" html tag with "wp_nav_menu" function?

You don't need a walker. You can pass 'items_wrap' through wp_nav_menu(): <?php wp_nav_menu( array( 'theme_location' => 'main-menu', 'menu_id' => '', 'items_wrap' ...
Stephan's user avatar
  • 51
5 votes
Accepted

How to properly insert a link to a template in WordPress?

WordPress doesn't work that way. In WordPress, none of the posts or pages that you visit actually exist anywhere on the disk. The content is grabbed from database and then the template files are ...
Johansson's user avatar
  • 15.3k
5 votes
Accepted

Enclosing Shortcode Within Another Enclosing Shortcode Breaks Output Functionality

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 ...
Michael Ecklund's user avatar
5 votes
Accepted

How do I add a custom css to all posts without affecting homepage css?

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 ...
kero's user avatar
  • 6,230
5 votes
Accepted

Make PHP work with HTML tags

From your code the proper structure would be if ( is_singular() ) { if (get_post_meta(get_the_ID(), 'square_image', true)) { echo '<img src="' . get_post_meta($post->ID, '...
Buttered_Toast's user avatar
4 votes

How do I use Shortcodes inside of HTML tags?

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=...
Crazycoolcam's user avatar
4 votes
Accepted

Attribute Quote Style in WordPress HTML

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 ...
db306's user avatar
  • 338
4 votes
Accepted

Adding a search form inside a div

The get_search_form() echos so it will always show up before returns. Use: get_search_form( false )
Christina's user avatar
  • 463
4 votes
Accepted

Play Video on Homepage Only

querySelector() returns null if no matches are found, so wrap the code that depends on imagineVideo in a conditional statement. var imagineVideo = document.querySelector('.page-id-36 .et_pb_video_box ...
Dave Romsey's user avatar
  • 17.8k
4 votes

How do I add HTML to a PHP function

You can use 'echo' (or 'print') to enclose HTML, but sometimes that gets a bit messy with complex HTML, not to mention having to escape quote/double-quote character. So try something like this: ...
Rick Hellewell's user avatar
3 votes

WordPress Shortcode and Dynamic CSS

The closest to a reference technique in core would be [gallery] shortcode. If you look at the source of implementing gallery_shortcode() function you'll see that it: Generates instance number (so ...
Rarst's user avatar
  • 99.7k
3 votes

In which directory do I find the HTML file of my wordpress pages?

You can find your root HTML file in here: /public_html/wp-content/themes/"YOUR THEME NAME"/framework/templates A file named header.php has to be in there.
S.A.F.'s user avatar
  • 41
3 votes

Appearance -> Menu -> Menu Structure : Add plain HTML code as an element

You can add your flag (plain) html into menu at last li tag. <?php function add_last_nav_item($items, $args) { if ($args->menu->slug == 'topbar-menu') { // change your menu slug name ...
Jignesh Patel's user avatar
3 votes
Accepted

Adding JSON Structured Data to WordPress

If you're creating the theme yourself, you can always use Schema Microata markup directly in the theme itself. As we can see in the below example, adding extra attributes to your HTML can make it ...
FaCE's user avatar
  • 534
3 votes

radio button is checked but display not check

In the WordPress back-end you have to use checked="checked" (stricter XHTML), because the CSS will not be applied otherwise: <input type="radio" name="colors" id="blue" checked="checked"> this ...
David Lee's user avatar
  • 3,891
3 votes

Adding a search form inside a div

The solution is to use get_search_form( false ). get_search_form() will output the search form. Since you are trying to use the result in a string context, you need the function to return the html in ...
Zelda's user avatar
  • 85
3 votes

Add a unique class to HTML tag/element

Why not just add the class directly to the tag? <html <?php language_attributes(); ?> class="page-id-<?php the_ID(); ?>">
Robert Went's user avatar
3 votes

How to display blog images using wordpress in existing project

Short answer: DON'T DO IT! Even if yesterday you said tomorrow! Including WordPress's core in some other files is the last thing you want to do. Instead, use an Ajax method and fill the content by ...
Johansson's user avatar
  • 15.3k

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