php - Wordpress shortcode filtering the_content modifies all posts in a list -


I am writing a plugin and have code like this:

  add_shortcode (' Test ',' testfunc '); Function testfunc () {add_filter ('the_content', 'mycontent', 20); } Mycontent function ($ content) {return "& lt; p style = 'color: red' & gt; additional material & lt; / p & gt;"; }   

I used the short code '[Examination]' on my posts a .

The problem occurs when the list of posts is shown - for example when the view of a category is used - the content has been changed to all - Not only with that shortcode code

Any idea how I can change this, so it only filters the code

Hi Solution is not a solution that uses a shortcode hook but it searches for it in content.

  function content_custom_shortcode ($ content) {// search for shortcode $ shortcodes = 'test'; preg_match ('/ \'. shortcode. '\' / s', $ content, $ matches); // If the custom shortcode return custom content is present then return content (if '' '' '$ shortcode'] ', $ matches) back "& lt; p style =' color: red '& gt; additional content & lt ; / P & gt ;, "; And then return $ content; } add_filter ('the_content', 'content_custom_shortcode', 20);    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -