Cách viết shortcode vào file PHP
Shortcode chỉ thực thi trong trình soạn thảo của WordPress thôi chứ ở các hoàn cảnh khác nó không hiểu. Do đó nếu bạn muốn chèn shortcode vào một file PHP thì phải sử dụng hàm do_shortcode() để nó thực thi. Ví dụ như sau:
<?php echo do_shortcode('[ten_shortcode]'); ?>
Cách viết shortcode vào widget Text
add_filter('widget_text', 'do_shortcode');
Mặc định widget Text sẽ không cho bạn chèn shortcode vào, nếu muốn nó thực thi thì bạn chỉ cần filter lại nó là xong. Chèn đoạn sau vào file functions.php
Như vậy là ở bài này bạn đã biết qua cách tạo một shortcode cơ bản là như thế nào, rồi tạo một shortcode có sử dụng tham số và mình cũng đã giải thích khá kỹ càng về nó (nên bài nó mới dài thế này).
Thật sự shortcode trong WordPress là một tính năng vô cùng mạnh mẽ để bạn có thể chèn một cái gì đó vào bài một cách nhanh chóng. Nhưng hãy cẩn thận khi dùng nó bởi vì nếu bạn đã dùng ở nhiều bài, sau này bạn không muốn dùng shortcode đó nữa rồi tắt đi, lúc đó mới thật sự là mệt.
Nếu bạn vẫn còn thắc mắc, vui lòng để lại bình luận nhé
I was suggested this website via my cousin. I am now
not positive whether or not this put up is written through him
as nobody else know such precise about my problem. You’re amazing!
Thanks!
Hey there! I know this is kind of off-topic but I had to
ask. Does building a well-established blog such as yours require a lot of work?
I am completely new to writing a blog but I do
write in my diary everyday. I’d like to start a blog so I will
be able to share my experience and thoughts online.
Please let me know if you have any recommendations or tips for new
aspiring bloggers. Appreciate it!
Excellent items from you, man. I’ve bear in mind your stuff prior to and you’re just too great.
I really like what you have bought right here, really like what you are stating and
the way by which you are saying it. You’re making it entertaining
and you still take care of to keep it wise. I cant wait to
read far more from you. That is actually a great web
site.
[url=http://dexamethasone2023.online/]dexamethasone 4 tablet[/url]
kantorbola99
Kantorbola situs slot online terbaik 2023 , segera daftar di situs kantor bola dan dapatkan promo terbaik bonus deposit harian 100 ribu , bonus rollingan 1% dan bonus cashback mingguan . Kunjungi juga link alternatif kami di kantorbola77 , kantorbola88 dan kantorbola99