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, $...
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()"></...
13
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()
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 ...
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 '...
7
votes
Accepted
Why do templates contain so many PHP tag pairs?
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 ...
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', '...
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(
'...
6
votes
Accepted
To echo or not to echo?
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 ...
6
votes
How do I add some HTML before & after the content for all posts?
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'...
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.
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']&...
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 ...
5
votes
Accepted
Do you need to escape hard coded plain text?
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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, '...
4
votes
Accepted
Insert HTML Page in WordPress Page
You can't because it's a non-secure page http but you're loading into an https page. It's called Mixed Content.
Adjust your protocol to // and hope it renders over https.
<iframe src="//...
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=...
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 ...
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 )
4
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' ...
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 ...
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:
...
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.
3
votes
To echo or not to echo?
First one
I don't know any preferred way on this, you can use both where which demands. Though the first one you mentioned contain bugs:
echo '<li><a href="' . get_permalink() . '" title="' ...
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
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
html × 1198php × 382
css × 259
javascript × 126
plugins × 102
functions × 70
jquery × 62
customization × 55
theme-development × 52
images × 49
posts × 47
forms × 47
themes × 43
shortcode × 42
plugin-development × 40
woocommerce-offtopic × 34
menus × 31
widgets × 27
ajax × 26
tags × 25
pages × 24
templates × 22
loop × 21
editor × 21
tinymce × 20